Chinaunix首页 | 论坛 | 博客
  • 博客访问: 207280
  • 博文数量: 59
  • 博客积分: 476
  • 博客等级: 下士
  • 技术积分: 530
  • 用 户 组: 普通用户
  • 注册时间: 2011-12-02 13:12
文章分类
文章存档

2012年(3)

2011年(56)

我的朋友

分类: 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;
}

阅读(2265) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~