使用esp_audio_pay 实现单曲循环播放功能遇到的问题
Posted: Tue Jul 13, 2021 12:41 pm
1.使用esp_audio_play 播放sd卡中的音乐,
2.然后再回调函数中查看播放状态,
3.待播放完后紧接着重新用esp_audio_play播放。
功能是可以实现,但是上一次播放完成后,衔接的下一次播放都要等25秒中。下面时有关的log
I (2388093) BS-X001: Entry audio call back function status is 4
I (2388103) BS-X001: Entry audio call back function media type is is 0
W (2388103) ESP_AUDIO_CTRL: [media_ctrl_stop]-Already stopped, status is FINISHED, phase:0
I (2388213) BS-X001: play music is file://sdcard/sleep_1.mp3
I (2408233) BS-X001: uart[1] event:
I (2408233) BS-X001: [UART DATA]: 5
I (2408233) BS-X001: [DATA EVT]:ff,55,0,0,54
I (2408233) BS-X001: [DATA EVT]:54
I (2408243) BS-X001: heartbeat frame
W (2413213) ESP_AUDIO_CTRL: Prepare play activity timeout(25 s)
W (2413213) AUDIO_PIPELINE: There are no listener registered
I (2413343) BS-X001: Entry audio call back function status is 1
I (2413343) BS-X001: Entry audio call back function media type is is 0
以下是有关代码:
2.然后再回调函数中查看播放状态,
3.待播放完后紧接着重新用esp_audio_play播放。
功能是可以实现,但是上一次播放完成后,衔接的下一次播放都要等25秒中。下面时有关的log
I (2388093) BS-X001: Entry audio call back function status is 4
I (2388103) BS-X001: Entry audio call back function media type is is 0
W (2388103) ESP_AUDIO_CTRL: [media_ctrl_stop]-Already stopped, status is FINISHED, phase:0
I (2388213) BS-X001: play music is file://sdcard/sleep_1.mp3
I (2408233) BS-X001: uart[1] event:
I (2408233) BS-X001: [UART DATA]: 5
I (2408233) BS-X001: [DATA EVT]:ff,55,0,0,54
I (2408233) BS-X001: [DATA EVT]:54
I (2408243) BS-X001: heartbeat frame
W (2413213) ESP_AUDIO_CTRL: Prepare play activity timeout(25 s)
W (2413213) AUDIO_PIPELINE: There are no listener registered
I (2413343) BS-X001: Entry audio call back function status is 1
I (2413343) BS-X001: Entry audio call back function media type is is 0
以下是有关代码:
Code: Select all
//第一次播放
ESP_LOGI(TAG, "play command,music number is %d",datas[3]);
if(play_status.playing_flag == true){
if(play_status.source == SRC_BT)
periph_bt_stop(test_handle->bt_periph);
esp_audio_stop(test_handle->player, TERMINATION_TYPE_NOW);
vTaskDelay(10);
}
char *url = NULL;
music_index = datas[3];
if(music_index < 10)
sdcard_list_choose(sdcard_list_handle, music_index, &url);
ESP_LOGI(TAG, "play music is %s",url);
esp_audio_media_type_set(test_handle->player, MEDIA_SRC_TYPE_MUSIC_SD);
esp_audio_play(test_handle->player, AUDIO_CODEC_TYPE_DECODER, url, 0);
play_status.playing_flag = true;
play_status.source = SRC_SD;
Code: Select all
//回调函数
void audio_service_cb(esp_audio_state_t *audio, void *ctx)
{
ESP_LOGI(TAG, "Entry audio call back function status is %d",audio->status);
ESP_LOGI(TAG, "Entry audio call back function media type is is %d",audio->media_src);
if((music_index !=0)&&(music_index < 10)){
if((audio->status == AUDIO_STATUS_FINISHED)&&\
(play_status.source == SRC_SD)){
esp_audio_stop(test_handle->player, TERMINATION_TYPE_NOW);
vTaskDelay(10);
char *url = NULL;
if(music_index < 10)
sdcard_list_choose(sdcard_list_handle, music_index, &url);
ESP_LOGI(TAG, "play music is %s",url);
esp_audio_media_type_set(test_handle->player, MEDIA_SRC_TYPE_MUSIC_SD);
esp_audio_play(test_handle->player, AUDIO_CODEC_TYPE_DECODER, url, 0);
play_status.playing_flag = true;
play_status.source = SRC_SD;
}
}
}