资源简介
居于linux的音频播放和停止,可以作为项目使用

代码片段和文件信息
/*
* mp3播放器控制程序
* 功能:
k1:播放、暂停
k2:停止播放
k3:上一首
k4:下一首
* 附加:歌曲自动循环播放
*
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
/*共享内存申请标记*/
#define PERM S_IRUSR|S_IWUSR
/*双向循环列表:存放歌曲名*/
struct song
{
char songname[20];
struct song *prev;
struct song *next;
};
/*孙子进程id号*/
static pid_t gradchild;
/*子进程id号*/
/*共享内存描述标记*/
int shmid;
pid_t pid;
char *p_addr;
/*播放标记*/
int first_key=1;
int play_flag=0;
/*************************************************
Function name: play
Parameter : struct song *
Description : 播放函数
Return : void
Argument : void
Autor & date : ada 091207
**************************************************/
void play(struct song *currentsong)
{
pid_t fd;
char *c_addr;
char *p;
int len;
char my_song[30]=“./mp3/song/“;
while(currentsong)
{
/*创建子进程,即孙子进程*/
fd = fork();
if(fd == -1)
{
perror(“fork“);
exit(1);
}
else if(fd == 0)
{
#if 1
/*把歌曲名加上根路径*/
strcat(my_song currentsong->songname);
p = my_song;
len = strlen(p);
/*去掉文件名最后的‘\n‘*/
my_song[len-1]=‘\0‘;
printf(“THIS SONG IS %s\n“ my_song);
#endif
//system(“aplay makerror.wav“);
execl(“/usr/bin/aplay“ “aplay“ my_song NULL);
sleep(1);
printf(“\n\n\n“);
}
else
{
/*内存映射*/
c_addr = shmat(shmid 0 0);
/*把孙子进程的id和当前播放歌曲的节点指针传入共享内存*/
memcpy(c_addr &fd sizeof(pid_t));
printf(“fd = %d\n“ fd);
memcpy(c_addr + sizeof(pid_t)+1 ¤tsong 4);
memcpy(&gradchild &fd sizeof(pid_t));
/*把孙子进程的pid传给父进程*/
/*使用wait阻塞孙子进程,直到孙子进程播放完才能被唤醒;
当被唤醒时,表示播放MP3期间没有按键按下,则继续顺序播放下一首MP3*/
if(fd == wait(NULL))
{
currentsong = currentsong->next;
printf(“THE NEXT SONG IS %s\n“ currentsong->songname);
}
}
}
}
/*************************************************
Function name: creat_song_list
Parameter : void
Description : 创建歌曲名的双向循环链表
Return : struct song *
Argument : void
Autor & date : ada 09.12.07
**************************************************/
struct song *creat_song_list(void)
{
FILE *fd;
size_t size;
size_t len;
char *line = NULL;
struct song *head;
struct song *p1;
struct song *p2;
system(“ls ./mp3/song > song_list“);
fd = fopen(“song_list““r“);
p1 = (struct song *)malloc(sizeof(struct song));
printf(“==================song list=====================\n“);
system(“ls ./mp3/song“);
printf(“\n“);
printf(“=================================================\n“);
size = getline(&line&lenfd);
strncpy(p1->songnamelinestrlen(line));
head = p1;
while((size = getline(&line&lenfd)) != -1)
{
p2 = p1;
p1 = (struct song *)malloc(sizeof(struct song));
strncpy(p1->songnamelinestrlen(line));
p2->next = p1;
p1->prev = p2;
}
p1->next
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 8440 2013-12-31 13:12 app实现音乐播放 暂停\play_app.c
目录 0 2014-02-13 23:04 app实现音乐播放 暂停\
- 上一篇:SLR1语法分析生成器
- 下一篇:自己制作卡拉OK歌曲
相关资源
- uboot到linux logo显示不间断 补丁
- UNIX/LINUX编程实践教程的源码
- Linux任务管理器
- linux应用层的华容道游戏源代码
- 我做的电子琴,21个音,一般歌曲基本
- DOS播放器 QuickViewPro破解版
- 使用 SoundPool 同时播放多个音频
- ubuntu9.10 可加载内核模块和字符设备驱
- MP3文件ID3v2ID3v2APEv2标签读取
- 音频测试软件
- js万能播放器,网页播放插件实例
- 操作系统实验——虚存管理实验
- linux下的发包工具sendip
- 尚观培训linux许巍关于c 的笔记和讲义
- 尚观培训linux董亮老师关于数据结构的
- linux 线程池源码 c 版
- linux C 电梯程序练习
- linux下用多进程同步方法解决生产者
- Linux 操作系统实验(全)
- Linux From Scratch 中文手册
- linux 网络实验 ftp程序
- 声音文件播放程序.可以播放WAV文件并
- Linux命令大全离线版&在线版
- Qt 播放音频文件
- 操作系统共享内存实验
- 模拟电路课程设计(音频放大电路设
- dos 下运行Linux 命令--gnu_utils
- linux 0.12内核源代码
- linux简易shell C实现
- linux实验报告及心得体会
评论
共有 条评论