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)) {
92 ANNOUNCEMENT_PIPELINE_TASK_PRIORITY);
95 ESP_LOGE(TAG,
"Failed to create announcement pipeline");
104 ESP_LOGE(TAG,
"Failed to create media pipeline");
109 ESP_LOGI(TAG,
"Set up speaker media player");
113 switch (pipeline_type) {
139 if (media_command.
file.has_value()) {
140 playlist_item.
file = media_command.
file.value();
148 if (media_command.
file.has_value()) {
165 this->
set_retry(
"unpause_med", 50, 3, [
this](
const uint8_t remaining_attempts) {
175 if (media_command.
file.has_value()) {
217 this->
set_retry(
"unpause_ann", 50, 3, [
this](
const uint8_t remaining_attempts) {
230 this->
set_retry(
"unpause_med", 50, 3, [
this](
const uint8_t remaining_attempts) {
315 ESP_LOGE(TAG,
"The media pipeline's file reader encountered an error.");
317 ESP_LOGE(TAG,
"The media pipeline's audio decoder encountered an error.");
326 ESP_LOGE(TAG,
"The announcement pipeline's file reader encountered an error.");
328 ESP_LOGE(TAG,
"The announcement pipeline's audio decoder encountered an error.");
335 uint32_t timeout_ms = 0;
351 }
else if (playlist_item.
file.has_value()) {
355 if (timeout_ms > 0) {
370 uint32_t timeout_ms = 0;
384 }
else if (playlist_item.
file.has_value()) {
388 if (timeout_ms > 0) {
404 if (this->
state != old_state) {
418 media_command.
file = media_file;
424 media_command.
enqueue = enqueue;
442 if (
call.get_media_url().has_value()) {
443 media_command.
url =
new std::string(
444 call.get_media_url().value());
446 if (
call.get_command().has_value()) {
456 if (
call.get_volume().has_value()) {
463 if (
call.get_command().has_value()) {
465 TickType_t ticks_to_wait = portMAX_DELAY;
478 traits.set_supports_pause(
true);
485 traits.get_supported_formats().push_back(this->
media_format_.value());
490 traits.get_supported_formats().push_back(media_format);
516 if (old_mute_state != mute_state) {
543 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_object_id_hash()
void trigger(Ts... x)
Inform the parent automation that the event has triggered.
value_type const & value() const
void add_on_state_callback(std::function< void(OTAState, float, uint8_t, OTAComponent *)> &&callback)
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
std::unique_ptr< T > make_unique(Args &&...args)
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