第一段代码使用popen调用mpayer程序
#include <stdio.h>
#include <stdlib.h>
int main(){
FILE * pp = NULL;
char data[1024];
if ((pp = popen("mplayer -slave -input file=/home/lvxibao/tt oh-little-town-of-bethlehem.mp3", "r")) != NULL)
{
while(!feof(pp)){
fgets(data,1024,pp);
printf("%s\n",data);
//在这里可获取很多有用的信息。如:长度,当前的时间等。
}
pclose(pp);
}
return 0;
}
第二段代码想命名管道里面发送控制mplayer的命令
#include <stdio.h>
#include <string.h>
int main (){
char c[20];
while(gets(c) != EOF){
FILE * fifo = fopen("/home/lvxibao/tt","w");
int i = strlen(c);
c[i] = '\n';
c[i+1] = '\0';
fputs(c,fifo);
puts(c);
fflush(fifo);
fclose(fifo);
}
return 0;
}
/*$ ./a.out
MPlayer SVN-r31628-4.4.4 (C) 2000-2010 MPlayer Team
mplayer: could not co