Linux下的MP3播放程序
来源:互联网 发布:手机淘宝登录界面 编辑:程序博客网 时间:2024/06/06 04:25
运行环境Centos 6.5
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; 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;}
阅读全文
0 0
- Linux下的MP3播放程序
- linux下的mp3播放器
- MyMinimad ── Linux下用libmad写的mp3解码播放程序
- MyMinimad ── Linux下用libmad写的mp3解码播放程序(二)
- MyMinimad ── Linux下用libmad写的mp3解码播放程序
- linux下mp3播放器xmms的安装
- 在linux环境下播放MP3
- 关于Android下的MP3播放器
- linux下面的 mp3播放器xmms
- linux MP3播放器的移植
- wince下MP3播放
- 改造taglib彻底解决amarok等kde下音乐播放程序播放mp3时的中文乱码问题!
- linux播放MP3.。。
- Linux 学习笔记3----Gstreamer 编写播放mp3程序。
- 在 Fedora 5 Linux 下实现了一个基于 libmad 的 MP3 流媒体播放器
- Linux(FC)下播放rm rmvb mp3 wma 等各种媒体文件的解决方法
- linux下使用libmad库实现mp3文件的解码、播放
- linux下C语言读MP3 的id tag,算出播放时间
- 洛谷P1341 无序字母对(欧拉回路)
- Xilinx zynq的资料获取总结
- 1048. 数字加密(20)
- POJ
- 如何在Zynq-7000上烧写PL Image
- Linux下的MP3播放程序
- npm、vue开发环境搭建及路由介绍
- 【数据库】4种 NoSQL数据库
- 剑指offer之找出字符串中第一个重复的字符
- PAT乙级1029
- web 基本概念辨异 —— URI 与 URL
- zynq学习笔记四:编译linux内核
- 如何创建maven项目就是1.7的环境
- Box2D中的距离计算