mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-30 22:53:59 +00:00 
			
		
		
		
	[speaker] Bugfix: Media player always unpauses when receiving a stop command (#8474)
This commit is contained in:
		| @@ -203,19 +203,37 @@ void SpeakerMediaPlayer::watch_media_commands_() { | |||||||
|           this->is_paused_ = true; |           this->is_paused_ = true; | ||||||
|           break; |           break; | ||||||
|         case media_player::MEDIA_PLAYER_COMMAND_STOP: |         case media_player::MEDIA_PLAYER_COMMAND_STOP: | ||||||
|  |           // Pipelines do not stop immediately after calling the stop command, so confirm its stopped before unpausing. | ||||||
|  |           // This avoids an audible short segment playing after receiving the stop command in a paused state. | ||||||
|           if (this->single_pipeline_() || (media_command.announce.has_value() && media_command.announce.value())) { |           if (this->single_pipeline_() || (media_command.announce.has_value() && media_command.announce.value())) { | ||||||
|             if (this->announcement_pipeline_ != nullptr) { |             if (this->announcement_pipeline_ != nullptr) { | ||||||
|               this->cancel_timeout("next_ann"); |               this->cancel_timeout("next_ann"); | ||||||
|               this->announcement_playlist_.clear(); |               this->announcement_playlist_.clear(); | ||||||
|               this->announcement_pipeline_->stop(); |               this->announcement_pipeline_->stop(); | ||||||
|  |               this->set_retry("unpause_ann", 50, 3, [this](const uint8_t remaining_attempts) { | ||||||
|  |                 if (this->announcement_pipeline_state_ == AudioPipelineState::STOPPED) { | ||||||
|  |                   this->announcement_pipeline_->set_pause_state(false); | ||||||
|  |                   return RetryResult::DONE; | ||||||
|  |                 } | ||||||
|  |                 return RetryResult::RETRY; | ||||||
|  |               }); | ||||||
|             } |             } | ||||||
|           } else { |           } else { | ||||||
|             if (this->media_pipeline_ != nullptr) { |             if (this->media_pipeline_ != nullptr) { | ||||||
|               this->cancel_timeout("next_media"); |               this->cancel_timeout("next_media"); | ||||||
|               this->media_playlist_.clear(); |               this->media_playlist_.clear(); | ||||||
|               this->media_pipeline_->stop(); |               this->media_pipeline_->stop(); | ||||||
|  |               this->set_retry("unpause_med", 50, 3, [this](const uint8_t remaining_attempts) { | ||||||
|  |                 if (this->media_pipeline_state_ == AudioPipelineState::STOPPED) { | ||||||
|  |                   this->media_pipeline_->set_pause_state(false); | ||||||
|  |                   this->is_paused_ = false; | ||||||
|  |                   return RetryResult::DONE; | ||||||
|  |                 } | ||||||
|  |                 return RetryResult::RETRY; | ||||||
|  |               }); | ||||||
|             } |             } | ||||||
|           } |           } | ||||||
|  |  | ||||||
|           break; |           break; | ||||||
|         case media_player::MEDIA_PLAYER_COMMAND_TOGGLE: |         case media_player::MEDIA_PLAYER_COMMAND_TOGGLE: | ||||||
|           if (this->media_pipeline_ != nullptr) { |           if (this->media_pipeline_ != nullptr) { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user