資源簡介
基于Linux系統(tǒng)的音樂播放器整個(gè)工程文件,可用
代碼片段和文件信息
/*
?*?????SD卡mp3播放器控制程序
?* ???功能:
? ?k1:播放、暫停
? ?k2:停止播放
? ?k3:上一首
? ?k4:下一首
?*?????附加:歌曲自動(dòng)循環(huán)播放SD卡/sdcard/song目錄中mp3歌曲
?*/
?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
/*共享內(nèi)存申請標(biāo)記*/
#define?PERM?S_IRUSR|S_IWUSR
/*雙向循環(huán)列表:存放歌曲名*/
struct?song
{
char?songname[20];
struct?song?*prev;
struct?song?*next;
};
/*孫子進(jìn)程id號(hào)*/
pid_t?gradchild;
/*子進(jìn)程id號(hào)*/
pid_t?pid;
/*共享內(nèi)存描述標(biāo)記*/
int?shmid;
char?*p_addr;
/*共享內(nèi)存內(nèi)容格式*/
/*|gradchild(孫子進(jìn)程PID)?|+?|空一個(gè)字節(jié)|+?currentsong(當(dāng)前播放列表的節(jié)點(diǎn)指針)|*/
/*播放標(biāo)記*/
int?first_key=1;
int?play_flag=0;
/*************************************************
Function?name:?play
Parameter????:?struct?song?*
Description ?:?播放函數(shù)
Return ?:?void
Argument?????:?void
**************************************************/
void?play(struct?song?*currentsong)
{
pid_t?fd;
char?*c_addr;
char?*p;
int?len;
char?my_song[30]=“/udisk/song/“;
while(currentsong)
{
/*創(chuàng)建子進(jìn)程,即孫子進(jìn)程*/
fd?=?fork();
if(fd?==?-1)
{
perror(“fork“);
exit(1);
}
else?if(fd?==?0)?//孫子進(jìn)程
{
/*把歌曲名加上根路徑*/
strcat(my_songcurrentsong->songname);
p?=?my_song;
len?=?strlen(p);
/*去掉文件名最后的‘\n‘*/
my_song[len-1]=‘\0‘;
printf(“THIS?SONG?IS?%s\n“my_song);
??????????????????????/*運(yùn)行madplay播放器,播放MP3*/
execl(“/bin/madplay““madplay“my_songNULL);//播放當(dāng)前列表MP3音樂
printf(“\n\n\n“);
}
else?//子進(jìn)程
{
/*內(nèi)存映射*/
c_addr?=?shmat(shmid00);
/*把孫子進(jìn)程的id和當(dāng)前播放歌曲的節(jié)點(diǎn)指針傳入共享內(nèi)存*/
memcpy(c_addr&fdsizeof(pid_t));
memcpy(c_addr?+?sizeof(pid_t)+1¤tsong4);
/*使用wait阻塞子進(jìn)程,直到孫子進(jìn)程播放完才能被喚醒;
??當(dāng)被喚醒時(shí),表示播放MP3期間沒有按鍵按下,則繼續(xù)順序播放下一首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 ?:?創(chuàng)建歌曲名的雙向循環(huán)鏈表
Return ?:?struct?song?*
Argument?????:?void
**************************************************/
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(“l(fā)s?/udisk/song?>song_list“);
fd?=?fopen(“song_list““r“);
p1?=?(struct?song?*)malloc(sizeof(struct?song));
printf(“==================================song?list=====================================\n“);
system(“l(fā)s?/sdcard/song“);
printf(“\n“);
printf(“================================================================================\n“);
size?=?getline(&line&lenfd);
strncpy(p1->songnamelinestrlen(line));
head?=?p1;
while((size?=?getline(&line&lenfd))?!=?-1)?//從文件中讀取一行,直到出錯(cuò)或者到文件尾EOF返回-1
{
p2?=?p1;
p1?=?(struct?song?*)malloc(sizeof(struct?song));
strncpy(p1->songnamelinestrlen(line));
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2014-04-10?15:53??嵌入式作業(yè)\
?????目錄???????????0??2014-04-10?16:30??嵌入式作業(yè)\app\
?????文件??????????78??2011-01-03?01:58??嵌入式作業(yè)\app\Makefile
?????文件??????597674??2014-04-10?16:30??嵌入式作業(yè)\app\mp3_pla
?????文件????????9003??2015-04-08?10:35??嵌入式作業(yè)\app\pla
?????目錄???????????0??2014-04-10?15:52??嵌入式作業(yè)\bin\
?????文件??????103392??2011-09-02?15:52??嵌入式作業(yè)\bin\madplay
?????目錄???????????0??2014-04-10?15:52??嵌入式作業(yè)\driver\
?????文件?????????247??2011-01-03?01:48??嵌入式作業(yè)\driver\.int_key_drv.ko.cmd
?????文件???????14060??2011-01-03?01:48??嵌入式作業(yè)\driver\.int_key_drv.mod.o.cmd
?????文件???????22926??2011-01-03?01:48??嵌入式作業(yè)\driver\.int_key_drv.o.cmd
?????目錄???????????0??2014-04-10?15:52??嵌入式作業(yè)\driver\.tmp_versions\
?????文件??????????77??2011-01-03?01:48??嵌入式作業(yè)\driver\.tmp_versions\int_key_drv.mod
?????文件????????8537??2011-04-05?21:58??嵌入式作業(yè)\driver\int_key_drv.c
?????文件?????????390??2010-09-16?16:35??嵌入式作業(yè)\driver\Makefile
?????目錄???????????0??2014-04-10?15:52??嵌入式作業(yè)\madplay\
?????文件??????338143??2006-11-04?14:06??嵌入式作業(yè)\madplay\libid3tag-0.15.1b.tar.gz
?????文件??????502379??2006-11-04?14:10??嵌入式作業(yè)\madplay\libmad-0.15.1b.tar.gz
?????文件??????590929??2006-11-04?14:10??嵌入式作業(yè)\madplay\madplay-0.15.2b.tar.gz
?????文件?????2357056??2011-09-02?16:01??嵌入式作業(yè)\madplay\madplay.tar.gz
?????文件???????75616??2011-11-16?14:33??嵌入式作業(yè)\madplay\madplay移植到mini2440開發(fā)手冊-賀工.pdf
?????文件??????496597??2006-11-04?14:13??嵌入式作業(yè)\madplay\zlib-1.2.3.tar.tar
?????目錄???????????0??2014-04-10?15:54??嵌入式作業(yè)\song\
?????文件????14246016??2014-03-01?22:12??嵌入式作業(yè)\song\cannon.mp3
?????文件?????9630855??2014-03-01?21:40??嵌入式作業(yè)\song\catchmybreath.mp3
?????文件?????9322578??2014-02-27?22:26??嵌入式作業(yè)\song\innocence.mp3
?????文件????10093671??2014-02-26?20:16??嵌入式作業(yè)\song\ykzzldx.mp3
?????文件?????3852781??2014-02-27?22:26??嵌入式作業(yè)\song\zuijiasunyou.mp3
評(píng)論
共有 條評(píng)論