OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/media/android/media_session.h" | 5 #include "content/browser/media/android/media_session.h" |
6 | 6 |
7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
8 #include "content/browser/media/android/media_session_observer.h" | 8 #include "content/browser/media/android/media_session_observer.h" |
9 #include "content/browser/web_contents/web_contents_impl.h" | 9 #include "content/browser/web_contents/web_contents_impl.h" |
10 #include "content/public/browser/web_contents.h" | 10 #include "content/public/browser/web_contents.h" |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 if (audio_focus_state_ != State::SUSPENDED) | 121 if (audio_focus_state_ != State::SUSPENDED) |
122 return; | 122 return; |
123 | 123 |
124 OnResumeInternal(SuspendType::SYSTEM); | 124 OnResumeInternal(SuspendType::SYSTEM); |
125 UpdateWebContents(); | 125 UpdateWebContents(); |
126 } | 126 } |
127 | 127 |
128 void MediaSession::Resume() { | 128 void MediaSession::Resume() { |
129 DCHECK(IsSuspended()); | 129 DCHECK(IsSuspended()); |
130 | 130 |
| 131 // Request audio focus again in case we lost it because another app started |
| 132 // playing while the playback was paused. |
| 133 audio_focus_state_ = RequestSystemAudioFocus(audio_focus_type_) |
| 134 ? State::ACTIVE |
| 135 : State::INACTIVE; |
| 136 if (audio_focus_state_ != State::ACTIVE) |
| 137 return; |
| 138 |
131 OnResumeInternal(SuspendType::UI); | 139 OnResumeInternal(SuspendType::UI); |
132 } | 140 } |
133 | 141 |
134 void MediaSession::Suspend() { | 142 void MediaSession::Suspend() { |
135 DCHECK(!IsSuspended()); | 143 DCHECK(!IsSuspended()); |
136 | 144 |
137 OnSuspendInternal(SuspendType::UI); | 145 OnSuspendInternal(SuspendType::UI); |
138 } | 146 } |
139 | 147 |
140 bool MediaSession::IsSuspended() const { | 148 bool MediaSession::IsSuspended() const { |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 | 229 |
222 audio_focus_state_ = State::INACTIVE; | 230 audio_focus_state_ = State::INACTIVE; |
223 UpdateWebContents(); | 231 UpdateWebContents(); |
224 } | 232 } |
225 | 233 |
226 void MediaSession::UpdateWebContents() { | 234 void MediaSession::UpdateWebContents() { |
227 static_cast<WebContentsImpl*>(web_contents())->OnMediaSessionStateChanged(); | 235 static_cast<WebContentsImpl*>(web_contents())->OnMediaSessionStateChanged(); |
228 } | 236 } |
229 | 237 |
230 } // namespace content | 238 } // namespace content |
OLD | NEW |