46static const uint32_t MEDIA_CONTROLS_QUEUE_LENGTH = 20;
48static const UBaseType_t MEDIA_PIPELINE_TASK_PRIORITY = 1;
49static const UBaseType_t ANNOUNCEMENT_PIPELINE_TASK_PRIORITY = 1;
51static const char *
const TAG =
"speaker_media_player";
61 if (this->
pref_.
load(&volume_restore_state)) {
69#ifdef USE_OTA_STATE_LISTENER
75 ANNOUNCEMENT_PIPELINE_TASK_PRIORITY);
78 ESP_LOGE(TAG,
"Failed to create announcement pipeline");
87 ESP_LOGE(TAG,
"Failed to create media pipeline");
92 ESP_LOGI(TAG,
"Set up speaker media player");
96 switch (pipeline_type) {
122 if (media_command.
file.has_value()) {
123 playlist_item.
file = media_command.
file.value();
131 if (media_command.
file.has_value()) {
148 this->
set_retry(
"unpause_med", 50, 3, [
this](
const uint8_t remaining_attempts) {
158 if (media_command.
file.has_value()) {
200 this->
set_retry(
"unpause_ann", 50, 3, [
this](
const uint8_t remaining_attempts) {
213 this->
set_retry(
"unpause_med", 50, 3, [
this](
const uint8_t remaining_attempts) {
286#ifdef USE_OTA_STATE_LISTENER
319 ESP_LOGE(TAG,
"The media pipeline's file reader encountered an error.");
321 ESP_LOGE(TAG,
"The media pipeline's audio decoder encountered an error.");
330 ESP_LOGE(TAG,
"The announcement pipeline's file reader encountered an error.");
332 ESP_LOGE(TAG,
"The announcement pipeline's audio decoder encountered an error.");
339 uint32_t timeout_ms = 0;
355 }
else if (playlist_item.
file.has_value()) {
359 if (timeout_ms > 0) {
374 uint32_t timeout_ms = 0;
388 }
else if (playlist_item.
file.has_value()) {
392 if (timeout_ms > 0) {
408 if (this->
state != old_state) {
422 media_command.
file = media_file;
428 media_command.
enqueue = enqueue;
446 if (
call.get_media_url().has_value()) {
447 media_command.
url =
new std::string(
448 call.get_media_url().value());
450 if (
call.get_command().has_value()) {
460 if (
call.get_volume().has_value()) {
467 if (
call.get_command().has_value()) {
469 TickType_t ticks_to_wait = portMAX_DELAY;
482 traits.set_supports_pause(
true);
489 traits.get_supported_formats().push_back(this->
media_format_.value());
494 traits.get_supported_formats().push_back(media_format);
520 if (old_mute_state != mute_state) {
547 if (volume < 0.001) {
virtual void mark_failed()
Mark this component as failed.
bool cancel_timeout(const std::string &name)
Cancel a timeout function.
void defer(const std::string &name, std::function< void()> &&f)
Defer a callback to the next loop() call.
void set_timeout(const std::string &name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a unique name.
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.
virtual ESPPreferenceObject make_preference(size_t length, uint32_t type, bool in_flash)=0
uint32_t get_preference_hash()
Get a unique hash for storing preferences/settings for this entity.
void trigger(const Ts &...x)
Inform the parent automation that the event has triggered.
value_type const & value() const
void add_global_state_listener(OTAGlobalStateListener *listener)
virtual void set_volume(float volume)
virtual void set_mute_state(bool mute_state)
OTAGlobalCallback * get_global_ota_callback()
Providing packet encoding functions for exchanging data with a remote host.
ESPPreferences * global_preferences
T remap(U value, U min, U max, T min_out, T max_out)
Remap value from the range (min, max) to (min_out, max_out).
optional< std::string > url
optional< audio::AudioFile * > file