全部博文(59)
分类: LINUX
2011-12-18 19:53:30
此处用了一个播放madplay的应用程序作为记录。里面有几个地方用到了kill,分别来进行播放音乐进程的开始、暂停、停止等操作:
#include
#include
#include
#include
#include
#include
#include
int main()
{
char ch;
int MIX_FD;
int iLeft = 60;
int iRight = 20;
int iLevel;
MIX_FD= open("/dev/mixer", O_WRONLY);
if (MIX_FD == -1)
{
perror("Error:open /dev/mixer error");
exit(1);
}
printf ("[a] Play \n");
printf ("[b] Pause \n");
printf ("[c] Resume\n");
printf ("[d] stop \n");
printf ("[+] Up Vol\n");
printf ("[-] Down Vol\n");
printf ("[e] Exit \n");
while(1)
{
printf("Please enter your choice: ");
scanf("%c",&ch);
printf("\n");
switch (ch)
{
case '+':
{
if(iLeft<100)
iLeft += 5;
iLevel = (iRight << 8) + iLeft;
ioctl(MIX_FD, MIXER_WRITE(SOUND_MIXER_VOLUME), &iLevel);
}
break;
case '-':
{
if(iLeft>20)
iLeft -= 5;
iLevel = (iRight << 8) + iLeft;
ioctl(MIX_FD, MIXER_WRITE(SOUND_MIXER_VOLUME), &iLevel);
}
break;
case 'a':
{
iLevel = (iRight << 8) + iLeft;
ioctl(MIX_FD, MIXER_WRITE(SOUND_MIXER_VOLUME), &iLevel);
system("./madplay /tmp/p.mp3 &"); //利用system函数调用madplay播放器播放*.mp3音乐
}
break;
case 'b':
{
system("killall -STOP madplay &"); //利用system函数调用killall命令将madplay暂停
}
break;
case 'c':
{
system("killall -CONT madplay &"); //利用system函数调用killall命令恢复madplay的播放
}
break;
case 'd':
{
system("killall -9 madplay"); //利用system函数调用killall命令将madplay终止掉
}
break;
case 'e':
{
goto exit;
}
}
}
exit: return 0;
}