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 e90daf417e6d72bb057719a550a15da5725e6b4f..9ee7456a1c650c75b97d0e7299e9791bcd531cf0 100644 |
--- a/content/browser/media/android/media_session.cc |
+++ b/content/browser/media/android/media_session.cc |
@@ -63,8 +63,6 @@ MediaSession::~MediaSession() { |
bool MediaSession::AddPlayer(MediaSessionObserver* observer, |
int player_id, |
Type type) { |
- observer->OnSetVolumeMultiplier(player_id, volume_multiplier_); |
- |
// If the audio focus is already granted and is of type Content, there is |
// nothing to do. If it is granted of type Transient the requested type is |
// also transient, there is also nothing to do. Otherwise, the session needs |
@@ -72,26 +70,28 @@ bool MediaSession::AddPlayer(MediaSessionObserver* observer, |
if (audio_focus_state_ == State::ACTIVE && |
(audio_focus_type_ == Type::Content || audio_focus_type_ == type)) { |
players_.insert(PlayerIdentifier(observer, player_id)); |
- return true; |
- } |
+ } else { |
+ State old_audio_focus_state = audio_focus_state_; |
+ State audio_focus_state = RequestSystemAudioFocus(type) ? State::ACTIVE |
+ : State::INACTIVE; |
+ SetAudioFocusState(audio_focus_state); |
+ audio_focus_type_ = type; |
- State old_audio_focus_state = audio_focus_state_; |
- State audio_focus_state = RequestSystemAudioFocus(type) ? State::ACTIVE |
- : State::INACTIVE; |
- SetAudioFocusState(audio_focus_state); |
- audio_focus_type_ = type; |
- |
- if (audio_focus_state_ != State::ACTIVE) |
- return false; |
+ if (audio_focus_state_ != State::ACTIVE) |
+ return false; |
- // The session should be reset if a player is starting while all players are |
- // suspended. |
- if (old_audio_focus_state != State::ACTIVE) |
- players_.clear(); |
+ // The session should be reset if a player is starting while all players are |
+ // suspended. |
+ if (old_audio_focus_state != State::ACTIVE) |
+ players_.clear(); |
- players_.insert(PlayerIdentifier(observer, player_id)); |
- UpdateWebContents(); |
+ players_.insert(PlayerIdentifier(observer, player_id)); |
+ UpdateWebContents(); |
+ } |
+ // Unmute audio for observers which may have started playing asynchronously in |
+ // a muted state while waiting for the focus approval. |
+ observer->OnSetVolumeMultiplier(player_id, volume_multiplier_); |
return true; |
} |
@@ -205,27 +205,6 @@ bool MediaSession::IsControllable() const { |
audio_focus_type_ == Type::Content; |
} |
-void MediaSession::ResetJavaRefForTest() { |
- j_media_session_.Reset(); |
-} |
- |
-bool MediaSession::IsActiveForTest() const { |
- return audio_focus_state_ == State::ACTIVE; |
-} |
- |
-MediaSession::Type MediaSession::audio_focus_type_for_test() const { |
- return audio_focus_type_; |
-} |
- |
-MediaSessionUmaHelper* MediaSession::uma_helper_for_test() { |
- return &uma_helper_; |
-} |
- |
-void MediaSession::RemoveAllPlayersForTest() { |
- players_.clear(); |
- AbandonSystemAudioFocusIfNeeded(); |
-} |
- |
void MediaSession::OnSuspendInternal(SuspendType type, State new_state) { |
DCHECK(new_state == State::SUSPENDED || new_state == State::INACTIVE); |
// UI suspend cannot use State::INACTIVE. |
@@ -289,6 +268,7 @@ void MediaSession::OnSetVolumeMultiplierInternal(double volume_multiplier) { |
MediaSession::MediaSession(WebContents* web_contents) |
: WebContentsObserver(web_contents), |
+ default_system_audio_focus_response_(true), |
audio_focus_state_(State::INACTIVE), |
audio_focus_type_(Type::Transient), |
volume_multiplier_(media::MediaPlayerAndroid::kDefaultVolumeMultiplier) { |
@@ -306,7 +286,7 @@ void MediaSession::Initialize() { |
bool MediaSession::RequestSystemAudioFocus(Type type) { |
// During tests, j_media_session_ might be null. |
if (j_media_session_.is_null()) |
- return true; |
+ return default_system_audio_focus_response_; |
JNIEnv* env = base::android::AttachCurrentThread(); |
DCHECK(env); |