Usage of esp_player_wrapper.c

vigyanabikshu
Posts: 4
Joined: Mon Apr 12, 2021 4:30 pm

Usage of esp_player_wrapper.c

Postby vigyanabikshu » Mon Apr 12, 2021 4:56 pm

I am trying to use esp_player_wrapper.c tp playback mp3 with controls, but fails. Below is my code and output.

void app_main(void)
{
unsigned long counter=0;

esp_log_level_set("*", ESP_LOG_WARN);
esp_log_level_set(TAG, ESP_LOG_INFO);

esp_audio_handle_t player = setup_player(esp_audio_callback_func, NULL);
printf("Player init...");
esp_player_init(player);
printf("Play /sdcard/folder/1.mp3");
int ret = esp_player_sdcard_music_play("/sdcard/folder/1.mp3", 0);
printf("Res:%d",ret);
//xTaskCreate(task_mp3playback, "task_mp3playback", 1024*4, (void *) "/sdcard/folder/1.mp3", configMAX_PRIORITIES, NULL);

while(1){
vTaskDelay(1000 / portTICK_PERIOD_MS);
printf("%lu\n",counter++);
}
}

void *setup_player(void *cb, void *ctx)
{
esp_audio_cfg_t cfg = {
.in_stream_buf_size = 4096, /*!< Input buffer size */
.out_stream_buf_size = 4096, /*!< Output buffer size */
.evt_que = NULL, /*!< Registered by uesr for receiving esp_audio event */
.resample_rate = 48000 /*!< sample rate */
};
esp_audio_handle_t handle = esp_audio_create(&cfg);
mem_assert(handle);

audio_element_handle_t fatfs_stream_reader, i2s_stream_writer, mp3_decoder;

ESP_LOGI(TAG, "[ 1 ] Mount sdcard");
// Initialize peripherals management
esp_periph_config_t periph_cfg = DEFAULT_ESP_PERIPH_SET_CONFIG();
esp_periph_set_handle_t set = esp_periph_set_init(&periph_cfg);

// Initialize SD Card peripheral
audio_board_sdcard_init(set, SD_MODE_1_LINE);

ESP_LOGI(TAG, "[3.1] Create fatfs stream to read data from sdcard");
fatfs_stream_cfg_t fatfs_cfg = FATFS_STREAM_CFG_DEFAULT();
fatfs_cfg.type = AUDIO_STREAM_READER;
fatfs_stream_reader = fatfs_stream_init(&fatfs_cfg);

ESP_LOGI(TAG, "[3.2] Create i2s stream to write data to codec chip");
i2s_stream_cfg_t i2s_cfg = I2S_STREAM_TX_PDM_CFG_DEFAULT();
i2s_cfg.type = AUDIO_STREAM_WRITER;
i2s_stream_writer = i2s_stream_init(&i2s_cfg);

ESP_LOGI(TAG, "[3.3] Create mp3 decoder to decode mp3 file");
mp3_decoder_cfg_t mp3_cfg = DEFAULT_MP3_DECODER_CONFIG();
mp3_decoder = mp3_decoder_init(&mp3_cfg);

ESP_LOGI(TAG, "[3.4] Register all elements to audio pipeline");
esp_audio_input_stream_add(handle, fatfs_stream_reader);
esp_audio_output_stream_add(handle, i2s_stream_writer);
esp_audio_codec_lib_add(handle, AUDIO_CODEC_TYPE_DECODER, mp3_decoder);

// Set default volume
esp_audio_vol_set(handle, 60);
AUDIO_MEM_SHOW(TAG);
ESP_LOGI(TAG, "esp_audio instance is:%p", handle);

return handle;
}

OUTPUT
Rebooting...
�0f�f����3�~��3�6~'��3R6����~�3~�����&wf& �!D����W[3��3[ǵ��s����������)�D����q�77����{f��"�;�(a�Sۤ��I2���?Lf'ݣ� ��1�bՙE (390) ESP_AUDIO_CTRL: The size of task stack(0) too small, line:286
I (390) parrot: [ 1 ] Mount sdcard
I (890) parrot: [3.1] Create fatfs stream to read data from sdcard
I (890) parrot: [3.2] Create i2s stream to write data to codec chip
I (940) parrot: [3.3] Create mp3 decoder to decode mp3 file
I (990) parrot: [3.4] Register all elements to audio pipeline
I (1070) parrot: Func:setup_player, Line:249, MEM Total:242292 Bytes

I (1160) parrot: esp_audio instance is:0x0
Player init...Play /sdcard/folder/1.mp3E (1210) ESP_AUDIO_CTRL: /home/gitlab-runner/builds/w2jWgEzx/0/adf/esp-adf-libs-source/esp_audio/src/media_ctrl.c:1144 (media_ctrl_media_src_set): Got NULL Pointer

jason.mao
Posts: 98
Joined: Mon Nov 19, 2018 2:05 am

Re: Usage of esp_player_wrapper.c

Postby jason.mao » Tue Apr 13, 2021 8:03 am

parrot: esp_audio instance is:0x0
Here is the root case. `esp_audio_handle_t handle = esp_audio_create(&cfg);` return NULL?

Who is online

Users browsing this forum: No registered users and 30 guests