| Index: content/browser/media/android/media_session.cc
|
| diff --git a/content/browser/media/android/media_session.cc b/content/browser/media/android/media_session.cc
|
| index a19e29eab89236838194ace2b349ad64c8183674..343842eb8b717a6f05b64f1cfa1a7a046e6ee2e6 100644
|
| --- a/content/browser/media/android/media_session.cc
|
| +++ b/content/browser/media/android/media_session.cc
|
| @@ -6,6 +6,8 @@
|
|
|
| #include "base/android/jni_android.h"
|
| #include "content/browser/media/android/media_session_observer.h"
|
| +#include "content/public/browser/web_contents.h"
|
| +#include "content/public/browser/web_contents_delegate.h"
|
| #include "jni/MediaSession_jni.h"
|
|
|
| namespace content {
|
| @@ -68,6 +70,7 @@ bool MediaSession::AddPlayer(MediaSessionObserver* observer,
|
| State old_audio_focus_state = audio_focus_state_;
|
| audio_focus_state_ = RequestSystemAudioFocus(type) ? State::Active
|
| : State::Suspended;
|
| + Type old_audio_focus_type = audio_focus_type_;
|
| audio_focus_type_ = type;
|
|
|
| if (audio_focus_state_ != State::Active)
|
| @@ -75,10 +78,15 @@ bool MediaSession::AddPlayer(MediaSessionObserver* observer,
|
|
|
| // The session should be reset if a player is starting while all players are
|
| // suspended.
|
| - if (old_audio_focus_state != State::Active)
|
| + if (old_audio_focus_state != State::Active) {
|
| + // Hide the controls if the type switched from Content to Transient.
|
| + if (audio_focus_type_ == Type::Transient)
|
| + HideMediaControlsIfNeeded(old_audio_focus_type);
|
| players_.clear();
|
| + }
|
|
|
| players_.insert(PlayerIdentifier(observer, player_id));
|
| + ShowMediaControlsIfNeeded(audio_focus_type_);
|
|
|
| return true;
|
| }
|
| @@ -105,10 +113,35 @@ void MediaSession::RemovePlayers(MediaSessionObserver* observer) {
|
|
|
| void MediaSession::OnSuspend(JNIEnv* env, jobject obj, jboolean temporary) {
|
| OnSuspend(temporary);
|
| +
|
| + if (temporary) {
|
| + // Reflect the paused state on the media controls.
|
| + ShowMediaControlsIfNeeded(audio_focus_type_);
|
| + } else {
|
| + HideMediaControlsIfNeeded(audio_focus_type_);
|
| + }
|
| }
|
|
|
| void MediaSession::OnResume(JNIEnv* env, jobject obj) {
|
| OnResume();
|
| + ShowMediaControlsIfNeeded(audio_focus_type_);
|
| +}
|
| +
|
| +void MediaSession::OnControlsPause() {
|
| + DCHECK(!IsPaused());
|
| +
|
| + // Since the playback can be resumed, it's a transient suspension.
|
| + OnSuspend(true);
|
| +}
|
| +
|
| +void MediaSession::OnControlsResume() {
|
| + DCHECK(IsPaused());
|
| +
|
| + OnResume();
|
| +}
|
| +
|
| +bool MediaSession::IsPaused() {
|
| + return audio_focus_state_ != State::Active;
|
| }
|
|
|
| void MediaSession::ResetJavaRefForTest() {
|
| @@ -123,6 +156,11 @@ MediaSession::Type MediaSession::audio_focus_type_for_test() const {
|
| return audio_focus_type_;
|
| }
|
|
|
| +void MediaSession::RemoveAllPlayersForTest() {
|
| + players_.clear();
|
| + AbandonSystemAudioFocusIfNeeded();
|
| +}
|
| +
|
| void MediaSession::OnSuspend(bool temporary) {
|
| if (temporary)
|
| audio_focus_state_ = State::TemporarilySuspended;
|
| @@ -178,6 +216,17 @@ void MediaSession::AbandonSystemAudioFocusIfNeeded() {
|
| }
|
|
|
| audio_focus_state_ = State::Suspended;
|
| + HideMediaControlsIfNeeded(audio_focus_type_);
|
| +}
|
| +
|
| +void MediaSession::ShowMediaControlsIfNeeded(Type audio_focus_type) {
|
| + if (audio_focus_type == Type::Content && web_contents()->GetDelegate())
|
| + web_contents()->GetDelegate()->ShowMediaControls(web_contents());
|
| +}
|
| +
|
| +void MediaSession::HideMediaControlsIfNeeded(Type audio_focus_type) {
|
| + if (audio_focus_type == Type::Content && web_contents()->GetDelegate())
|
| + web_contents()->GetDelegate()->HideMediaControls(web_contents());
|
| }
|
|
|
| } // namespace content
|
|
|