Linux下的MP3播放程序
2017-10-01 23:10
197 查看
运行环境Centos 6.5
C语言
实现mp3的大部分功能。
C语言
实现mp3的大部分功能。
/*********************************************************************** > File Name: mp3.c > Author: YangKun > Mail: yangkungetit@163.com > Created Time: Sat 30 Sep 2017 11:24:28 PM PDT ************************************************************************/ #include<string.h> #include<stdio.h> #include<stdlib.h> #include<dirent.h> #include <sys/types.h> typedef struct _node { char name[256]; struct _node* prev; struct _node* next; }node; node* head = NULL; node* cur =NULL; int first = 1; void play() { if(first==1) { first=0; char buf[1024]={}; sprintf(buf,"madplay -o wav:- %s 2>/dev/null | aplay 2>/dev/null &",cur->name); system(buf); } else if(first==0) { system("killall -19 madplay"); } } void continue_play() { system("killall -18 madplay"); } void Insert_list(char* name) { node* p=(node*)malloc(sizeof(node)); memset(p,0x00,sizeof(node)); strcpy(p->name,name); if(head==NULL) { p->prev=p->next=p; head = p; cur=p; return ; } p->prev=head->prev; p->next=head; head->prev->next=p; head->prev=p; } void prev() { system("killall -9 madplay"); cur = cur->prev; first = 1; play(); } void next() { system("killall -9 madplay"); cur = cur->next; first = 1; play(); } void show_list() { node* p=head; aff7 if(p==NULL) { printf("no music in list\n"); exit(0); } int i=1; do { printf("%d-->%s\n",i++,p->name); p=p->next; }while(p!=head); } void near_music() { printf("Currently playing:%s\n",cur->name); printf("Last Piece Of Song:%s\n",cur->prev->name); printf("Next Song:%s\n",cur->next->name); } void add_music() { DIR *pdir=opendir("/mp3"); if ( pdir == NULL ) perror("opendir"),exit(1); struct dirent *p=NULL; char pathname[256]={}; while((p=readdir(pdir))!=NULL) { if(p->d_name[0]=='.') continue; memset(pathname,0x00,sizeof(pathname)); sprintf(pathname,"/mp3/%s",p->d_name); Insert_list(pathname); } closedir(pdir); } int menu() { int i; printf("\n+-------------------------------------------------------------+\n"); printf("| | \n"); printf("| Welcome to MP3 PLAYER | \n"); printf("| | \n"); printf("| 1.Play\\stop | \n"); printf("| 2.continue | \n"); printf("| 3.prev song | \n"); printf("| 4.next song | \n"); printf("| | \n"); printf("|_____________________________________________________________| \n"); printf("choose->"); scanf("%d",&i); return i; } void start_mp3() { int input = 1; do { show_list(); switch(menu()) { case 1: play(); break; case 2: continue_play(); break; case 3: prev(); break; case 4: next(); break; default: printf("again\n"); break; } while(input) { near_music(); printf("^-^choose:"); scanf("%d",&input); switch(input) { case 0: break; case 1: play(); break; case 2: continue_play(); break; case 3: prev(); break; case 4: next(); break; default: printf("err operation\n"); } } }while(1); } int main() { add_music(); start_mp3(); return 0; }
相关文章推荐
- MyMinimad ── Linux下用libmad写的mp3解码播放程序(二)
- MyMinimad ── Linux下用libmad写的mp3解码播放程序
- Linux 学习笔记3----Gstreamer 编写播放mp3程序。
- MyMinimad ── Linux下用libmad写的mp3解码播放程序
- LINUX下播放WAV的C程序。利用OSS接口
- python 写作简单的mp3程序 - linux系统
- linux下C语言读MP3 的id tag,算出播放时间
- 解决Linux下面Firefox无法播放mp3的问题
- Linux环境下用c语言写的播放wav文件的小程序
- 改造taglib彻底解决amarok等kde下音乐播放程序播放mp3时的中文乱码问题!
- linux 播放声音文件程序代码
- Linux 终端播放 MP3 格式音频软件
- Linux(FC)下播放rm rmvb mp3 wma 等各种媒体文件的解决方法
- 向嵌入式MP3迈进--在linux C程序中调用madplay控制命令
- 简单的使用libmad的low-level api和portaudio写的播放mp3的小程序
- linux mp3播放及分析
- Linux基于Gstreamer的傻瓜组装式mp3播放
- 基于Linux ALSA音频驱动的wav文件解析及播放程序 2012
- 将python程序打包成exe文件和播放mp3
- linux下在命令行中用默认程序打开特定文件如.mp3 .jpg 甚至是网页也可以