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 float FIRST_BOOT_DEFAULT_VOLUME = 0.5f;
53static 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 ESP_LOGI(TAG,
"Set up speaker media player");
115 switch (pipeline_type) {
141 if (media_command.
file.has_value()) {
142 playlist_item.
file = media_command.
file.value();
150 if (media_command.
file.has_value()) {
167 this->
set_retry(
"unpause_med", 50, 3, [
this](
const uint8_t remaining_attempts) {
177 if (media_command.
file.has_value()) {
219 this->
set_retry(
"unpause_ann", 50, 3, [
this](
const uint8_t remaining_attempts) {
232 this->
set_retry(
"unpause_med", 50, 3, [
this](
const uint8_t remaining_attempts) {
317 ESP_LOGE(TAG,
"The media pipeline's file reader encountered an error.");
319 ESP_LOGE(TAG,
"The media pipeline's audio decoder encountered an error.");
328 ESP_LOGE(TAG,
"The announcement pipeline's file reader encountered an error.");
330 ESP_LOGE(TAG,
"The announcement pipeline's audio decoder encountered an error.");
337 uint32_t timeout_ms = 0;
353 }
else if (playlist_item.
file.has_value()) {
357 if (timeout_ms > 0) {
372 uint32_t timeout_ms = 0;
386 }
else if (playlist_item.
file.has_value()) {
390 if (timeout_ms > 0) {
406 if (this->
state != old_state) {
420 media_command.
file = media_file;
426 media_command.
enqueue = enqueue;
444 if (
call.get_media_url().has_value()) {
445 media_command.
url =
new std::string(
446 call.get_media_url().value());
448 if (
call.get_command().has_value()) {
458 if (
call.get_volume().has_value()) {
465 if (
call.get_command().has_value()) {
467 TickType_t ticks_to_wait = portMAX_DELAY;
480 traits.set_supports_pause(
true);
487 traits.get_supported_formats().push_back(this->
media_format_.value());
492 traits.get_supported_formats().push_back(media_format);
518 if (old_mute_state != mute_state) {
545 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