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

 /* mpg3V1 */  
 // header files  
 #include<unistd.h>  
 #include<stdio.h>  
 #include<error.h>  
 #include<errno.h>  
 //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"  
  if(playlist==NULL)  
   {  
    error(1,errno,"cannot open the playlist");  
   }  
  while(filename!=NULL)  
   {  
    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  
    if(pid_mpg==-1)  
      {  
       error(1,errno,"cant fork child process");  
      }  
    else if(pid==0)//child process  
      {  
       char *arg[]={"mpg123",filename,NULL};  
       //launch mpg player here  
      }  
    else  
      {  
       //parent process. waits for child to complete playing  
       int stat,ret;  
       ret=wait(&stat);  
       //insert code here corresponding to child process  
      }}  

Comments

Popular posts from this blog

Generating 16k ROM using Xilinx IP COREGEN and simulating it in modelsim

Setting up atalanta ATPG to work on Linux

Sparse matrix - 3 tuple representation