时间:2021-05-20
实例代码如下:
#include <stdio.h>#include<dirent.h>#include<stdlib.h>#include<unistd.h>#include<string.h>typedef struct node_ node_t;struct node_{ char* name;//gequming node_t * prev; node_t * next;};node_t *head = NULL;int first=1;//diyicibofnagnode_t * cur =NULL;//dangqianbofangenum{STOP,PAUSE,PLAY};int status = STOP;void List_init(void){ head = malloc(sizeof(node_t)); memset(head,0x00,sizeof(node_t)); head->next = head->prev=head;}void list_insert(const char* name){ node_t *p = malloc(sizeof(node_t)); memset(p,0x00,sizeof(node_t)); p->name = malloc(strlen(name)+1); strcpy(p->name,name); p->next = head->next; p->prev = head; head->next->prev = p; head->next = p;}int menu(void){ printf("*************menu************************\n"); printf("1. play/pause\n"); printf("2. next\n"); printf("3. prev\n"); printf("4. stop\n"); printf("5. exit\n"); printf("**************************************\n"); list_show(); int choose =4; do{ printf(" > "); scanf("%d",&choose); if(choose>=0&&choose<=4) break; printf("choose invalid\n"); while(getchar()!='\n'); }while(1); return choose;}void list_show(void){ node_t *p = head->next; while(p!=head){ printf("%s ",p->name); if(p==cur) printf("<<==cur"); printf("\n"); p = p->next; }}void load_music(const char * path){ DIR * pdir = opendir(path); if(pdir == NULL){ perror("opendir"); exit(1);}struct dirent * p = NULL;while((p=readdir(pdir))!=NULL){if(p->d_name[0]=='.') continue; list_insert(p->d_name);}closedir(pdir);}void playPause(){ if(first==1){ char buf[1024] = {}; sprintf(buf,"madplay -o wav:- ./music/Music/%s 2> /dev/null | aplay 2>/dev/null &",cur->name); system(buf); first = 0; status = PLAY; }else{ if(status==PLAY){ system("killall -SIGSTOP aplay"); status = PAUSE; }else if(status==PAUSE){ system("killall -SIGCONT aplay"); status = PLAY; } }}void stop(){ system("killall -SIGKILL aplay"); first=1;}void next(){ stop(); cur = cur ->next; if(cur==head){ cur = cur->next; } playPause();}void prev(){ stop(); cur = cur->prev; if(cur==head){ cur= cur->prev; } playPause();}int main(int args,char * argv[]){ List_init(); load_music("./music/Music");if(head->next!=head) cur = head->next; //printf("%s\n",cur->name); //list_show(); do{ int choose = menu(); switch(choose){ case 1: playPause(); break; case 2: next(); break; case 3: prev(); break; case 4: stop(); break; case 0: printf("thanks"); system("killall -SIGKILL aplay"); exit(0); break; default: break; //do nothing; }}while(1); return 0;}实例效果图片如下:
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
本文实例为大家分享了js+audio实现音乐播放器的具体代码,供大家参考,具体内容如下音乐播放器*{margin:0;padding:0;-moz-user-s
本文主要介绍了原生JS实现音乐播放器的示例代码,分享给大家,具体如下:效果图音乐播放器播放控制播放进度条控制歌词显示及高亮播放模式设置播放器属性归类按照播放器的
本文实例为大家分享了android音乐播放器的具体代码,供大家参考,具体内容如下话不多说先上效果前言写这个音乐播放器实在是迫不得已。因为我们Andoird课程要
QQ音乐播放器中的定时停止播放音乐怎么设置?在QQ音乐播放器中,有个停止播放音乐的功能,可以对计算机设置定时停止播放音乐。那么,具体在QQ音乐播放器中该怎么设置
本文实例讲述了js实现可兼容IE、FF、Chrome、Opera及Safari的音乐播放器。分享给大家供大家参考。具体实现方法如下:/**音乐播放器*@para