mplayer播放器管道重构版

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

主要实现及功能:

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(
评论 7
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值