主要实现及功能:
1,播放,暂停及继续,上一页下一页,上一首下一首和退出
2,歌曲结束根据播放模式来自动下一首
3,可根据不同格式导入歌曲
4,ANSI控制码实现简单的界面制作
5, 通过管道来向mplayer播放器发送指令
6, 在播歌曲滑动显示
主要技术点:
父进程捕捉SIGCHLD信号通过信号处理函数wait收尸来获得mplayer的退出状态,当mplayer正常结束时,信号处理函数创建一个分离的线程重新打开mplayer播放器根据播放模式来自动播放下一首,main线程通过temp标志位来获取mplayer的控制权
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <glob.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/stat.h>
#include <unistd.h>
#include <termios.h>
#include <fcntl.h>
#include <sys/wait.h>
#include <pthread.h>
#include "mplayer.h"
#include "double_link.h"
#define PATTERN "/home/ll/Music/*.mp3"
#define FIFOPATH "music.fifo"
#define MUSICSIZE 256
#define OPTSIZE 512
#define NAMEBUFSIZE 256
#define ROW 15
#define LINE 10
/* 音乐名字数组*/
char musicBuff[MUSICSIZE] = {0};
/* 链表头结点 */
LList_st *head = NULL;
/* 链表当前位置 */
llist *cur = NULL;
/* 进程号 */
pid_t pid;
/* golb参数 */
glob_t buff;
/* 播放模式 */
int playWay = ORDER;
/* 播放器状态 */
int tmp = 0;
/* 主界面 */
void interface()
{
int i, j, k;
printf("\033[2J\033[5;25H\033[44m--====================--------------------\033[0m\n");
printf("%c[6;25H",'\033');
for (i = 0; i < ROW; i++)
{
printf("\033[44m||\033[0m");
for (j = 0; j < LINE; j++)
{
printf(" ");
}
printf("\033[44m||\t\t||\033[0m\n\033[24C");
}
printf("\033[6;35H%s\n","歌单");
printf("\033[6;53H\033[42m%s\033[0m\n","按键说明");
printf("\033[8;52H%s\n","播放 'b'");
printf("\033[9;52H%s\n","暂停 'p'");
printf("\033[10;52H%s\n","退出 'q'");
printf("\033[12;52H%s\n","上一首 'a'");
printf(

该博客介绍了一个使用ANSI控制码和管道与mplayer交互的音乐播放器的实现。它支持播放、暂停、下一首、上一首、播放模式切换等功能,并能根据播放模式自动播放。此外,它还能导入不同格式的歌曲,通过简单的界面展示歌单。
最低0.47元/天 解锁文章
1万+

被折叠的 条评论
为什么被折叠?



