46 static const uint32_t MEDIA_CONTROLS_QUEUE_LENGTH = 20;
48 static const UBaseType_t MEDIA_PIPELINE_TASK_PRIORITY = 1;
49 static const UBaseType_t ANNOUNCEMENT_PIPELINE_TASK_PRIORITY = 1;
51 static const float FIRST_BOOT_DEFAULT_VOLUME = 0.5f;
53 static const char *
const TAG =
"speaker_media_player";
63 if (this->
pref_.
load(&volume_restore_state)) {
94 ANNOUNCEMENT_PIPELINE_TASK_PRIORITY);
97 ESP_LOGE(TAG,
"Failed to create announcement pipeline");
106 ESP_LOGE(TAG,
"Failed to create media pipeline");
111 this->media_speaker_->add_audio_output_callback(
112 [
this](uint32_t new_playback_ms, uint32_t remainder_us, uint32_t pending_ms, uint32_t write_timestamp) {
121 ESP_LOGI(TAG,
"Set up speaker media player");
125 switch (pipeline_type) {
141 esp_err_t err = ESP_OK;
147 if (new_url || new_file) {
206 ESP_LOGE(TAG,
"Error starting the audio pipeline: %s", esp_err_to_name(err));
323 ESP_LOGE(TAG,
"The media pipeline's file reader encountered an error.");
325 ESP_LOGE(TAG,
"The media pipeline's audio decoder encountered an error.");
334 ESP_LOGE(TAG,
"The announcement pipeline's file reader encountered an error.");
336 ESP_LOGE(TAG,
"The announcement pipeline's audio decoder encountered an error.");
343 uint32_t timeout_ms = 0;
359 }
else if (playlist_item.
file.has_value()) {
363 if (timeout_ms > 0) {
385 uint32_t timeout_ms = 0;
399 }
else if (playlist_item.
file.has_value()) {
403 if (timeout_ms > 0) {
418 if (this->
state != old_state) {
440 media_command.
enqueue = enqueue;
487 TickType_t ticks_to_wait = portMAX_DELAY;
500 traits.set_supports_pause(
true);
507 traits.get_supported_formats().push_back(this->
media_format_.value());
512 traits.get_supported_formats().push_back(media_format);
538 if (old_mute_state != mute_state) {
565 if (volume < 0.001) {
value_type const & value() const
bool cancel_timeout(const std::string &name)
Cancel a timeout function.
virtual void set_volume(float volume)
optional< audio::AudioFile * > file
void set_timeout(const std::string &name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a unique name.
void defer(const std::string &name, std::function< void()> &&f)
Defer a callback to the next loop() call.
void trigger(Ts... x)
Inform the parent automation that the event has triggered.
void status_set_error(const char *message="unspecified")
optional< std::string > url
ESPPreferences * global_preferences
void add_on_state_callback(std::function< void(OTAState, float, uint8_t, OTAComponent *)> &&callback)
void status_clear_error()
virtual ESPPreferenceObject make_preference(size_t length, uint32_t type, bool in_flash)=0
virtual void mark_failed()
Mark this component as failed.
Implementation of SPI Controller mode.
OTAGlobalCallback * get_global_ota_callback()
uint32_t get_object_id_hash()
virtual void set_mute_state(bool mute_state)