Hi all,
I have an application program which keeps reading an audio file from a directory one after the other , once a file is chosen it keeps sending data in terms of 60000 bytes to a specified socket. This is written into another file "x.mp3" and mplayer is called. Again next 60000 bytes are read and same procedure is followed till end of file.
here is my code which does the above work
#include<stdio.h>
#include<dirent.h>
#include<string.h>
#include<errno.h>
#include<sys/types.h>
#include<stdlib.h>
#include <arpa/inet.h> /* for sockaddr_in and inet_addr() */
#include <unistd.h> /* for close() */
#define FALSE 0
#define TRUE !FALSE
void DieWithError(char *errorMessage);
int main()
{
DIR *d = opendir("sun");
struct dirent *ent;
int count = 0,x;
char filePath[20];
const char filepa[20]="sun/";
unsigned char funcall[100] = "mplayer ";
FILE *fp,*fp1;
int sock; /* Socket descriptor */
struct sockaddr_in echoServAddr; /* Echo server address */
unsigned short echoServPort; /* Echo server port */
char song[20];
char temp[20];
char songname[20] = "x.mp3 ";
char tmp_funccall[100];
FILE *file;
unsigned long buf1[200000];
if ((sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0)
DieWithError( "socket () failed") ;
memset(&echoServAddr, 0, sizeof(echoServAddr)); /* Zero out structure */
echoServAddr.sin_family = AF_INET; /* Internet addr family */
echoServAddr.sin_addr.s_addr = inet_addr("127.0.0.1"); /* Server IP address */
echoServAddr.sin_port = htons(9500);
ent = readdir(d);
while(ent)
{
x = (strcmp(ent->d_name,"..")) && (strcmp(ent->d_name,"."));
if(x != 0)
{
strcpy(filePath,filepa);
printf("\n%s\n",ent->d_name);
strcat(filePath,ent->d_name);
printf("\n%s-filepath\n",filePath);
file = fopen(filePath,"r");
if (file == NULL)
{
printf("\nno file");
}
while(!feof(file))
{
fread(&buf1,60000,1,file);
sendto(sock,buf1,60000, 0, (struct sockaddr *)&echoServAddr, sizeof(echoServAddr)) ;
fp1 = fopen("x.mp3","wb");
fwrite(buf1,60000,1,fp1);
strcpy(song,songname);
strcpy(tmp_funccall,funcall) ;
strcat(tmp_funccall,song);
printf("func %s\n",tmp_funccall);
system(tmp_funccall);
fclose(fp1);
}
fclose(file);
}
ent = readdir(d);
}
closedir(d);
close(sock);
exit(0);
return 0;
}
void DieWithError(char *errorMessage)
{
perror (errorMessage) ;
exit(1);
}
I get the following message when mplayer is called , but works fine. Am not getting why I get that message which is highlighted in red.
func mplayer x.mp3
MPlayer 1.0rc2-4.1.0 (C) 2000-2007 MPlayer Team
CPU: Intel(R) Pentium(R) 4 CPU 3.00GHz (Family: 15, Model: 3, Stepping: 4)
CPUflags: MMX: 1 MMX2: 1 3DNow: 0 3DNow2: 0 SSE: 1 SSE2: 1
Compiled for x86 CPU with extensions: MMX MMX2 SSE SSE2
Playing x.mp3.
Audio file file format detected.
==========================================================================
Opening audio decoder: [mp3lib] MPEG layer-2, layer-3
mpg123: Can't rewind stream by 1047 bits!
AUDIO: 44100 Hz, 2 ch, s16le, 128.0 kbit/9.07% (ratio: 16000->176400)
Selected audio codec: afm: mp3lib (mp3lib MPEG layer-2, layer-3)
==========================================================================
AO: [oss] 44100Hz 2ch s16le (2 bytes per sample)
Video: no video
Starting playback...
A: 3.2 (03.2) of 3.0 (03.0) 0.6%
Exiting... (End of file)
func mplayer x.mp3
MPlayer 1.0rc2-4.1.0 (C) 2000-2007 MPlayer Team
CPU: Intel(R) Pentium(R) 4 CPU 3.00GHz (Family: 15, Model: 3, Stepping: 4)
CPUflags: MMX: 1 MMX2: 1 3DNow: 0 3DNow2: 0 SSE: 1 SSE2: 1
Compiled for x86 CPU with extensions: MMX MMX2 SSE SSE2
Playing x.mp3.
Audio file file format detected.
==========================================================================
Opening audio decoder: [mp3lib] MPEG layer-2, layer-3
mpg123: Can't rewind stream by 1563 bits!
AUDIO: 44100 Hz, 2 ch, s16le, 128.0 kbit/9.07% (ratio: 16000->176400)
Selected audio codec: afm: mp3lib (mp3lib MPEG layer-2, layer-3)
==========================================================================
AO: [oss] 44100Hz 2ch s16le (2 bytes per sample)
Video: no video
Starting playback...
A: 3.2 (03.2) of 3.0 (03.0) 0.6%
Exiting... (End of file)