Chromium Code Reviews| 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..2d7ea09db225836f6391dd4d3bcb4a3dc2b8023e 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,16 @@ 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 && |
| + old_audio_focus_type == Type::Content) |
| + UpdateMediaControls(); |
|
mlamouri (slow - plz ping)
2015/06/24 16:15:02
With the new model of calling UpdateMediaControls(
whywhat
2015/06/24 18:36:15
Indeed. Done.
|
| players_.clear(); |
| + } |
| players_.insert(PlayerIdentifier(observer, player_id)); |
| + UpdateMediaControls(); |
| return true; |
| } |
| @@ -104,11 +113,35 @@ void MediaSession::RemovePlayers(MediaSessionObserver* observer) { |
| } |
| void MediaSession::OnSuspend(JNIEnv* env, jobject obj, jboolean temporary) { |
| - OnSuspend(temporary); |
| + OnSuspendInternal(temporary); |
| + UpdateMediaControls(); |
| } |
| void MediaSession::OnResume(JNIEnv* env, jobject obj) { |
| - OnResume(); |
| + OnResumeInternal(); |
| + UpdateMediaControls(); |
| +} |
| + |
| +void MediaSession::OnControlsPause() { |
| + DCHECK(!IsPaused()); |
| + |
| + // Since the playback can be resumed, it's a transient suspension. |
| + OnSuspendInternal(true); |
| +} |
| + |
| +void MediaSession::OnControlsResume() { |
| + DCHECK(IsPaused()); |
| + |
| + OnResumeInternal(); |
| +} |
| + |
| +bool MediaSession::IsPaused() { |
| + return audio_focus_state_ != State::Active; |
| +} |
| + |
| +bool MediaSession::IsControllable() { |
| + return audio_focus_state_ != State::Suspended && |
| + audio_focus_type_ == Type::Content; |
| } |
| void MediaSession::ResetJavaRefForTest() { |
| @@ -123,7 +156,12 @@ MediaSession::Type MediaSession::audio_focus_type_for_test() const { |
| return audio_focus_type_; |
| } |
| -void MediaSession::OnSuspend(bool temporary) { |
| +void MediaSession::RemoveAllPlayersForTest() { |
| + players_.clear(); |
| + AbandonSystemAudioFocusIfNeeded(); |
| +} |
| + |
| +void MediaSession::OnSuspendInternal(bool temporary) { |
| if (temporary) |
| audio_focus_state_ = State::TemporarilySuspended; |
| else |
| @@ -133,7 +171,7 @@ void MediaSession::OnSuspend(bool temporary) { |
| it.observer->OnSuspend(it.player_id); |
| } |
| -void MediaSession::OnResume() { |
| +void MediaSession::OnResumeInternal() { |
| audio_focus_state_ = State::Active; |
| for (const auto& it : players_) |
| @@ -178,6 +216,12 @@ void MediaSession::AbandonSystemAudioFocusIfNeeded() { |
| } |
| audio_focus_state_ = State::Suspended; |
| + UpdateMediaControls(); |
| +} |
| + |
| +void MediaSession::UpdateMediaControls() { |
| + if (web_contents()->GetDelegate()) |
| + web_contents()->GetDelegate()->UpdateMediaControls(web_contents()); |
| } |
| } // namespace content |