| 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..854785725b24905f1ec1709aae302652ee8af295 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 {
|
| @@ -79,6 +81,7 @@ bool MediaSession::AddPlayer(MediaSessionObserver* observer,
|
| players_.clear();
|
|
|
| players_.insert(PlayerIdentifier(observer, player_id));
|
| + UpdateMediaControls();
|
|
|
| return true;
|
| }
|
| @@ -104,11 +107,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 +150,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 +165,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 +210,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
|
|
|