使用 tinyplay 播放音乐(重复播放,按照次数播放) popen 的使用
static void *ThreadFunc(void *arg) { while(1){ pthread_mutex_lock(&playbackMutex);//mydebugUs; if(audio_playback_flag==0){pthread_cond_wait(&playbackCond, &playbackMutex);mydebugUs;} pthread_mutex_unlock(&playbackMutex);//mydebugUs; // //2023.11.23 使用进程进行播放测试 //mydebugUs; // FILE *fp = popen("ps -ef | grep tinyplay | grep -v grep | awk '{print $1}' | xargs kill -9", "r"); // if (fp) { char out[256];while (fgets(out, sizeof(out), fp) != NULL) { printf(out); } pclose(fp); } audio_playback_flag=0;//清空标记 system("ps -ef | grep tinyplay | grep -v grep | awk '{print $1}' | xargs kill -9"); //mydebugUs; usleep(1000); //mydebugUs; char cmd[1024]; //int flag=loop_num;//=0xFFFFFFFF snprintf(cmd,1024,"./tinyplay_num.sh %s %d &",filename,loop_num); //mydebugMsg(cmd); system(cmd); //mydebugUs; continue; } } static int audio_playback_flag = 0; static int audio_playback_flag_closed = 0; static unsigned int loop_num = 1;//循环次数 static unsigned int loop_minutes = 0;//循环多长时间,设置这个,则设置次数失效 static char filename[1024];//文件名 static pthread_cond_t playbackCond=PTHREAD_COND_INITIALIZER; static pthread_mutex_t playbackMutex; static pthread_t playbackTid; void AudioInitFunc(void){ pthread_mutex_init(&playbackMutex, NULL); pthread_cond_init(&playbackCond, NULL); pthread_create(&playbackTid, NULL, ThreadFunc, NULL); audio_playback_flag=0; } //名称播放 int AudioPlaybackStartFileName(char* name,int loopType,int num){ if(strlen(name)>=sizeof(filename)){ AudioSetStatePlayback(AUDIO_INFO_ERROR_FILENAME_LEN); return -1; } strncpy(filename,name,sizeof(filename)); if(loopType==AUDIO_LOOP_NUM){ loop_num=num;loop_minutes=0; } else if(loopType==AUDIO_LOOP_MINUTES){ loop_minutes=num;loop_num=0; } else if(loopType==AUDIO_LOOP_KEEP_ALIVE){ loop_minutes=0xFFFFFFFF;loop_num=0xFFFFFFFF; } else {loop_num=1;loop_minutes=0;} //WAKE UP audio_playback_flag = 2; pthread_mutex_lock(&playbackMutex);//mydebugUs; pthread_cond_signal(&playbackCond);//mydebugUs; pthread_mutex_unlock(&playbackMutex);//mydebugUs; return 0; }
//
//