功能背景参考一。
note:播放/暂停主要时给进程发送停止和恢复信号,进程并没有退出。以下为c语言例程源码。
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <string.h>
#define MAX_SONGS 3
char *songs[MAX_SONGS] = {
"/mnt/hgfs/share/poxiao.mp3",
"/mnt/hgfs/share/talk_anymore.mp3",
"/mnt/hgfs/share/attention.mp3"
};
int current_song = 0;
int play_mode = 0; // 0: 单曲播放, 1: 单曲循环, 2: 列表循环
pid_t player_pid = 0;
int is_paused = 0; // 标记是否处于暂停状态
void handle_sigchld(int sig) {
int status;
pid_t pid = waitpid(-1, &status, WUNTRACED | WCONTINUED);
if (pid > 0 && pid == player_pid) {
if (WIFEXITED(status)) {
// 子进程已正常结束
printf("歌曲播放结束\n");
if (play_mode == 1) { // 单曲循环
play_song(current_song);
} else if (play_mode == 2) { // 列表循环
current_song = (curren

最低0.47元/天 解锁文章
488

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



