Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(138)

Unified Diff: content/browser/media/android/media_session.cc

Issue 1159113006: [Android] A prototype of the interactive media notification. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added browser tests Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..68f61d672d8cfed7cb6786d15392908166d07670 100644
--- a/content/browser/media/android/media_session.cc
+++ b/content/browser/media/android/media_session.cc
@@ -6,8 +6,11 @@
#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"
+
mlamouri (slow - plz ping) 2015/06/18 16:43:22 nit: remove empty line
mlamouri (slow - plz ping) 2015/06/22 14:34:17 double nit: you didn't do it.
whywhat 2015/06/23 19:39:10 Do you check the diff that you commented on? :)
namespace content {
DEFINE_WEB_CONTENTS_USER_DATA_KEY(MediaSession);
@@ -68,6 +71,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 +79,15 @@ 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)
+ HideMediaControlsIfNeeded(old_audio_focus_type);
players_.clear();
+ }
players_.insert(PlayerIdentifier(observer, player_id));
+ ShowMediaControlsIfNeeded(audio_focus_type_);
return true;
}
@@ -105,10 +114,35 @@ void MediaSession::RemovePlayers(MediaSessionObserver* observer) {
void MediaSession::OnSuspend(JNIEnv* env, jobject obj, jboolean temporary) {
OnSuspend(temporary);
+
+ if (temporary) {
+ // Reflect the paused state on the media controls.
+ ShowMediaControlsIfNeeded(audio_focus_type_);
+ } else {
+ HideMediaControlsIfNeeded(audio_focus_type_);
+ }
mlamouri (slow - plz ping) 2015/06/18 16:43:22 Shouldn't that be in the ::OnSuspend(bool) method?
whywhat 2015/06/19 16:00:34 OnSuspend(bool) is called from the controls so it
mlamouri (slow - plz ping) 2015/06/22 14:34:17 Hmm, I see. Could you rename OnSuspend() to OnSusp
whywhat 2015/06/23 19:39:10 Ok. On 2015/06/22 at 14:34:17, Mounir Lamouri wro
}
void MediaSession::OnResume(JNIEnv* env, jobject obj) {
OnResume();
+ ShowMediaControlsIfNeeded(audio_focus_type_);
mlamouri (slow - plz ping) 2015/06/18 16:43:22 ditto
whywhat 2015/06/19 16:00:34 ditto
+}
+
+void MediaSession::OnControlsPause() {
+ DCHECK(!IsPaused());
+
+ // Since the playback can be resumed, it's a transient suspension.
+ OnSuspend(true);
+}
+
+void MediaSession::OnControlsResume() {
+ DCHECK(IsPaused());
+
+ OnResume();
+}
+
+bool MediaSession::IsPaused() {
+ return audio_focus_state_ != State::Active;
}
void MediaSession::ResetJavaRefForTest() {
@@ -123,6 +157,11 @@ MediaSession::Type MediaSession::audio_focus_type_for_test() const {
return audio_focus_type_;
}
+void MediaSession::RemoveAllPlayersForTest() {
+ players_.clear();
+ AbandonSystemAudioFocusIfNeeded();
+}
+
void MediaSession::OnSuspend(bool temporary) {
if (temporary)
audio_focus_state_ = State::TemporarilySuspended;
@@ -178,6 +217,17 @@ void MediaSession::AbandonSystemAudioFocusIfNeeded() {
}
audio_focus_state_ = State::Suspended;
+ HideMediaControlsIfNeeded(audio_focus_type_);
+}
+
+void MediaSession::ShowMediaControlsIfNeeded(Type audio_focus_type) {
+ if (audio_focus_type == Type::Content && web_contents()->GetDelegate())
+ web_contents()->GetDelegate()->ShowMediaControls(web_contents());
+}
+
+void MediaSession::HideMediaControlsIfNeeded(Type audio_focus_type) {
+ if (audio_focus_type == Type::Content && web_contents()->GetDelegate())
mlamouri (slow - plz ping) 2015/06/18 16:43:22 Why do we need to check the |audio_focus_type|?
whywhat 2015/06/19 16:00:34 Because we don't want to have controls for transie
+ web_contents()->GetDelegate()->HideMediaControls(web_contents());
}
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698