/********** 播放音乐 播放音乐时,若有按键消息则返回 ***********/ void play_song(int uart_fd, struct douban_radio *douban) { int index = 0; char index_buff[5] = {0}; char command_buff[1] = {PLAY_INDEX}; write(uart_fd, command_buff, 1); if(uart_read(uart_fd, index_buff, 5, 1) == 5) { index = atoi(index_buff); printf("play index is read %d!\n", index); printf("%s\n", douban->items[index].url); douban_radio(douban->items[index].url); } }
void player_thread(void* parameter) { rt_err_t result; struct player_request request; while(1) { /* get request from message queue */ result = rt_mq_recv(player_thread_mq, (void*)&request, sizeof(struct player_request), RT_WAITING_FOREVER); if (result == RT_EOK) { switch (request.type) { case PLAYER_REQUEST_PLAY_SINGLE_FILE: if ((strstr(request.fn, ".mp3") != RT_NULL) || (strstr(request.fn, ".MP3") != RT_NULL)) { is_playing = RT_TRUE; player_notify_play(); /* get music tag information */ mp3(request.fn); player_notify_stop(); is_playing = RT_FALSE; } else if ((strstr(request.fn, ".wav") != RT_NULL) || (strstr(request.fn, ".WAV") != RT_NULL)) { is_playing = RT_TRUE; player_notify_play(); wav(request.fn); player_notify_stop(); is_playing = RT_FALSE; } else if ((strstr(request.fn, "http://") == request.fn || (strstr(request.fn, "HTTP://") == request.fn ))) { is_playing = RT_TRUE; player_notify_play(); ice_mp3(request.fn, request.station); /* notfiy net buffer worker to stop */ net_buf_stop_job(); player_notify_stop(); is_playing = RT_FALSE; } else if (strstr(request.fn, "douban://") == request.fn) { is_playing = RT_TRUE; player_notify_play(); douban_radio(request.fn, request.station); /* notfiy net buffer worker to stop */ net_buf_stop_job(); player_notify_stop(); is_playing = RT_FALSE; } break; } } } }