| 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 44a4b2a9184904af5d9ad00611709d9eb7a2470d..577353a21d3b283c7784c80d07875258478d3ddb 100644
|
| --- a/content/browser/media/android/media_session.cc
|
| +++ b/content/browser/media/android/media_session.cc
|
| @@ -52,7 +52,7 @@ MediaSession* MediaSession::Get(WebContents* web_contents) {
|
|
|
| MediaSession::~MediaSession() {
|
| DCHECK(players_.empty());
|
| - DCHECK(audio_focus_state_ == State::Suspended);
|
| + DCHECK(audio_focus_state_ == State::Inactive);
|
| }
|
|
|
| bool MediaSession::AddPlayer(MediaSessionObserver* observer,
|
| @@ -70,7 +70,7 @@ bool MediaSession::AddPlayer(MediaSessionObserver* observer,
|
|
|
| State old_audio_focus_state = audio_focus_state_;
|
| audio_focus_state_ = RequestSystemAudioFocus(type) ? State::Active
|
| - : State::Suspended;
|
| + : State::Inactive;
|
| audio_focus_type_ = type;
|
|
|
| if (audio_focus_state_ != State::Active)
|
| @@ -108,35 +108,44 @@ void MediaSession::RemovePlayers(MediaSessionObserver* observer) {
|
| }
|
|
|
| void MediaSession::OnSuspend(JNIEnv* env, jobject obj, jboolean temporary) {
|
| - OnSuspendInternal(temporary);
|
| + if (audio_focus_state_ != State::Active)
|
| + return;
|
| +
|
| + OnSuspendInternal(SuspendType::System);
|
| + if (!temporary)
|
| + audio_focus_state_ = State::Inactive;
|
| UpdateWebContents();
|
| }
|
|
|
| void MediaSession::OnResume(JNIEnv* env, jobject obj) {
|
| - OnResumeInternal();
|
| + if (audio_focus_state_ != State::Suspended)
|
| + return;
|
| +
|
| + OnResumeInternal(SuspendType::System);
|
| UpdateWebContents();
|
| }
|
|
|
| -void MediaSession::Resume() {
|
| +void MediaSession::Resume(SuspendType type) {
|
| DCHECK(IsSuspended());
|
|
|
| - OnResumeInternal();
|
| + OnResumeInternal(type);
|
| }
|
|
|
| -void MediaSession::Suspend() {
|
| +void MediaSession::Suspend(SuspendType type) {
|
| DCHECK(!IsSuspended());
|
|
|
| // Since the playback can be resumed, it's a transient suspension.
|
| - OnSuspendInternal(true);
|
| + OnSuspendInternal(type);
|
| }
|
|
|
| bool MediaSession::IsSuspended() const {
|
| + // TODO(mlamouri): should be == State::Suspended.
|
| return audio_focus_state_ != State::Active;
|
| }
|
|
|
| bool MediaSession::IsControllable() const {
|
| - // Only content type media session can be controllable unless it's stopped.
|
| - return audio_focus_state_ != State::Suspended &&
|
| + // Only content type media session can be controllable unless it is inactive.
|
| + return audio_focus_state_ != State::Inactive &&
|
| audio_focus_type_ == Type::Content;
|
| }
|
|
|
| @@ -157,17 +166,18 @@ void MediaSession::RemoveAllPlayersForTest() {
|
| AbandonSystemAudioFocusIfNeeded();
|
| }
|
|
|
| -void MediaSession::OnSuspendInternal(bool temporary) {
|
| - if (temporary)
|
| - audio_focus_state_ = State::TemporarilySuspended;
|
| - else
|
| - audio_focus_state_ = State::Suspended;
|
| +void MediaSession::OnSuspendInternal(SuspendType type) {
|
| + audio_focus_state_ = State::Suspended;
|
| + suspend_type_ = type;
|
|
|
| for (const auto& it : players_)
|
| it.observer->OnSuspend(it.player_id);
|
| }
|
|
|
| -void MediaSession::OnResumeInternal() {
|
| +void MediaSession::OnResumeInternal(SuspendType type) {
|
| + if (suspend_type_ != type && type != SuspendType::UI)
|
| + return;
|
| +
|
| audio_focus_state_ = State::Active;
|
|
|
| for (const auto& it : players_)
|
| @@ -176,7 +186,7 @@ void MediaSession::OnResumeInternal() {
|
|
|
| MediaSession::MediaSession(WebContents* web_contents)
|
| : WebContentsObserver(web_contents),
|
| - audio_focus_state_(State::Suspended),
|
| + audio_focus_state_(State::Inactive),
|
| audio_focus_type_(Type::Transient) {}
|
|
|
| void MediaSession::Initialize() {
|
| @@ -200,7 +210,7 @@ bool MediaSession::RequestSystemAudioFocus(Type type) {
|
| }
|
|
|
| void MediaSession::AbandonSystemAudioFocusIfNeeded() {
|
| - if (audio_focus_state_ == State::Suspended || !players_.empty())
|
| + if (audio_focus_state_ == State::Inactive || !players_.empty())
|
| return;
|
|
|
| // During tests, j_media_session_ might be null.
|
| @@ -210,7 +220,7 @@ void MediaSession::AbandonSystemAudioFocusIfNeeded() {
|
| Java_MediaSession_abandonAudioFocus(env, j_media_session_.obj());
|
| }
|
|
|
| - audio_focus_state_ = State::Suspended;
|
| + audio_focus_state_ = State::Inactive;
|
| UpdateWebContents();
|
| }
|
|
|
|
|