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

Unified Diff: content/public/android/java/src/org/chromium/content_public/browser/MediaSessionObserver.java

Issue 2453623003: Decouple MediaSession messages from WebContents (full patch) (Closed)
Patch Set: nit Created 4 years, 1 month 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/public/android/java/src/org/chromium/content_public/browser/MediaSessionObserver.java
diff --git a/content/public/android/java/src/org/chromium/content_public/browser/MediaSessionObserver.java b/content/public/android/java/src/org/chromium/content_public/browser/MediaSessionObserver.java
new file mode 100644
index 0000000000000000000000000000000000000000..fd789ded767928340da05c3081a929b24a390bbf
--- /dev/null
+++ b/content/public/android/java/src/org/chromium/content_public/browser/MediaSessionObserver.java
@@ -0,0 +1,66 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.content_public.browser;
+
+import android.support.annotation.Nullable;
+
+import org.chromium.content.browser.MediaSessionImpl;
+import org.chromium.content_public.common.MediaMetadata;
+
+/**
+ * This class is Java implementation of native MediaSessionObserver. The class receives media
+ * session messages from Java {@link MediaSession}, which acts acts as a proxy forwarding messages
+ * comming from the native MediaSession.
+ */
+public abstract class MediaSessionObserver {
+ private MediaSessionImpl mMediaSession;
+
+ /**
+ * Construct a MediaSessionObserver and start observing |mediaSession|.
+ */
+ protected MediaSessionObserver(MediaSession mediaSession) {
+ mMediaSession = (MediaSessionImpl) mediaSession;
+ mMediaSession.addObserver(this);
+ }
+
+ /**
+ * @return The observed media session.
+ */
+ @Nullable
+ public final MediaSession getMediaSession() {
+ return mMediaSession;
+ }
+
+ /**
+ * Called when the observed media session is destroyed.
+ *
+ * Gives subclass a chance to do clean up. After the whole loop over
+ * {@link MediaSessionObserver}s has been finished, {@link MediaSessionObserver#getMediaSession}
+ * will return null.
+ */
+ public void mediaSessionDestroyed() {}
+
+ /**
+ * Called when the observed {@link MediaSession} state has changed.
+ * @param isControllable If the session can be resumed or suspended.
+ * @param isSuspended if the session currently suspended or not.
+ */
+ public void mediaSessionStateChanged(boolean isControllable, boolean isSuspended) {}
+
+ /**
+ * Called when the {@link MediaSession} metadata has changed.
+ * @param metadata the new MediaMetadata after change.
+ */
+ public void mediaSessionMetadataChanged(MediaMetadata metadata) {}
+
+ /**
+ * Stop observing the media session. Users must explicitly call this before dereferencing the
+ * observer.
+ */
+ public final void stopObserving() {
+ if (mMediaSession == null) return;
+ mMediaSession.removeObserver(this);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698