Skip to content

Commit a37d90f

Browse files
committed
audio: add null check in play_audio
This is to prevent a crash when playing audio if the ESP Audio player is not initialized.
1 parent d2083fe commit a37d90f

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

main/audio.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ static void play_audio(const char *uri)
9999
reset_timer(hdl_display_timer, config_get_int("display_timeout", DEFAULT_DISPLAY_TIMEOUT), false);
100100
display_set_backlight(true, false);
101101

102+
if (hdl_ea == NULL) {
103+
ESP_LOGE(TAG, "audio_play called with hdl_ea=NULL, skip audio playback");
104+
return;
105+
}
106+
102107
audio_err_t err = esp_audio_play(hdl_ea, AUDIO_CODEC_TYPE_DECODER, uri, 0);
103108

104109
if (err == ESP_ERR_AUDIO_OPEN) {

0 commit comments

Comments
 (0)