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) {
151 if (media_command.
file.has_value()) {
152 playlist_item.
file = media_command.
file.value();
160 if (media_command.
file.has_value()) {
177 this->
set_retry(
"unpause_med", 50, 3, [
this](
const uint8_t remaining_attempts) {
187 if (media_command.
file.has_value()) {
229 this->
set_retry(
"unpause_ann", 50, 3, [
this](
const uint8_t remaining_attempts) {
242 this->
set_retry(
"unpause_med", 50, 3, [
this](
const uint8_t remaining_attempts) {
328 ESP_LOGE(TAG,
"The media pipeline's file reader encountered an error.");
330 ESP_LOGE(TAG,
"The media pipeline's audio decoder encountered an error.");
339 ESP_LOGE(TAG,
"The announcement pipeline's file reader encountered an error.");
341 ESP_LOGE(TAG,
"The announcement pipeline's audio decoder encountered an error.");
348 uint32_t timeout_ms = 0;
364 }
else if (playlist_item.
file.has_value()) {
368 if (timeout_ms > 0) {
390 uint32_t timeout_ms = 0;
404 }
else if (playlist_item.
file.has_value()) {
408 if (timeout_ms > 0) {
424 if (this->
state != old_state) {
438 media_command.
file = media_file;
444 media_command.
enqueue = enqueue;
463 media_command.
url =
new std::string(
485 TickType_t ticks_to_wait = portMAX_DELAY;
498 traits.set_supports_pause(
true);
505 traits.get_supported_formats().push_back(this->
media_format_.value());
510 traits.get_supported_formats().push_back(media_format);
536 if (old_mute_state != mute_state) {
563 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 set_retry(const std::string &name, uint32_t initial_wait_time, uint8_t max_attempts, std::function< RetryResult(uint8_t)> &&f, float backoff_increase_factor=1.0f)
Set an retry function with a unique name.
optional< std::string > url
ESPPreferences * global_preferences
void add_on_state_callback(std::function< void(OTAState, float, uint8_t, OTAComponent *)> &&callback)
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)