Thursday, February 2, 2012

Playing a playlist of MP3 files using the mpg player in Linux

 /* mpg3V1 */  
 // header files  
 //main func  
 int main(int argc, char *argv[])  
  File *playlist;//file pointer for playlist  
  char filename[256];//getting filename from the playlist  
  pid_t pid_mpg;//the pid of child process for launching mpg player  
  playlist=fopen("/home/abishek/Music/playlist.txt","r");//reads the playlist intp fp "playlist"  
    error(1,errno,"cannot open the playlist");  
    filename=fgets(filename,sizeof(filename),playlist);//gets first filename from playlist  
    if(filename==NULL)//checking end of file  
       printf("end of file reached");  
       return 0;  
    pid_mpg=fork();//branching child process cp->mpg123 pp->wait  
       error(1,errno,"cant fork child process");  
    else if(pid==0)//child process  
       char *arg[]={"mpg123",filename,NULL};  
       //launch mpg player here  
       //parent process. waits for child to complete playing  
       int stat,ret;  
       //insert code here corresponding to child process  

No comments:

Post a Comment