fix: arduino media player sets wrong state for announcements (#6849)

Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
This commit is contained in:
Mischa Siekmann 2024-06-07 21:43:22 +02:00 committed by GitHub
parent 861a23d039
commit 8718e15a6a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 4 deletions

View file

@ -27,6 +27,11 @@ void I2SAudioMediaPlayer::control(const media_player::MediaPlayerCall &call) {
this->start();
}
}
if (this->state == media_player::MEDIA_PLAYER_STATE_ANNOUNCING) {
this->is_announcement_ = true;
}
if (call.get_volume().has_value()) {
this->volume = call.get_volume().value();
this->set_volume_(volume);
@ -171,9 +176,8 @@ void I2SAudioMediaPlayer::start_() {
if (this->current_url_.has_value()) {
this->audio_->connecttohost(this->current_url_.value().c_str());
this->state = media_player::MEDIA_PLAYER_STATE_PLAYING;
if (this->is_announcement_.has_value()) {
this->state = this->is_announcement_.value() ? media_player::MEDIA_PLAYER_STATE_ANNOUNCING
: media_player::MEDIA_PLAYER_STATE_PLAYING;
if (this->is_announcement_) {
this->state = media_player::MEDIA_PLAYER_STATE_ANNOUNCING;
}
this->publish_state();
}
@ -202,6 +206,7 @@ void I2SAudioMediaPlayer::stop_() {
this->high_freq_.stop();
this->state = media_player::MEDIA_PLAYER_STATE_IDLE;
this->publish_state();
this->is_announcement_ = false;
}
media_player::MediaPlayerTraits I2SAudioMediaPlayer::get_traits() {

View file

@ -78,7 +78,7 @@ class I2SAudioMediaPlayer : public Component, public media_player::MediaPlayer,
HighFrequencyLoopRequester high_freq_;
optional<std::string> current_url_{};
optional<bool> is_announcement_{};
bool is_announcement_{false};
};
} // namespace i2s_audio