Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 package org.chromium.content_public.browser; | |
| 6 | |
| 7 import org.chromium.base.annotations.CalledByNative; | |
| 8 import org.chromium.base.annotations.JNINamespace; | |
| 9 import org.chromium.content_public.common.MediaMetadata; | |
| 10 | |
| 11 /** | |
| 12 * The class for listening to native {@link MediaSession} and operating on it. I t is the Java | |
| 13 * counterpart of {@link MediaSessionDelegateAndroid}. The Java object and its l inked native object | |
| 14 * must notify each other when anyone of them is destroyed. Clients of this clas s should create a | |
| 15 * {@link MediaSessionDelegate} object and explicitly call | |
| 16 * {@link WebContents#addMediaSessionDelegate} with the object as an argument. C lients of this class | |
| 17 * should also call {@link MediaSessionDelegate#disconnectMediaSession} when der eferencing the | |
| 18 * object. | |
| 19 */ | |
| 20 @JNINamespace("content") | |
| 21 public class MediaSessionDelegate { | |
| 22 // The native MediaSessionDelegateAndroid object | |
| 23 private long mNativeMediaSessionDelegateAndroid; | |
| 24 | |
| 25 /** | |
| 26 * Disconnects this delegate from the associated MediaSession. Clients of th is class must call | |
| 27 * this method when dereferencing this object. The clean up is done in | |
| 28 * {@link MediaSessionDelegate#mediaSessionDisconnected}. | |
| 29 */ | |
| 30 public final void disconnectMediaSession() { | |
| 31 if (hasNativeMediaSession()) { | |
| 32 nativeDisconnectMediaSession(mNativeMediaSessionDelegateAndroid); | |
| 33 } | |
| 34 } | |
| 35 | |
| 36 /** | |
| 37 * Called when this {@link MediaSessionDelegate} has been disconnected from a native | |
| 38 * {@link MediaSession}. | |
| 39 */ | |
| 40 public void mediaSessionDisconnected() {} | |
| 41 | |
| 42 /** | |
| 43 * Called when the native {@link MediaSession} state has changed. | |
| 44 * @param isControllable Whether the native {@link MediaSession} is controll able. | |
| 45 * @param isSuspended Whether the native {@link MediaSession} is suspended. | |
| 46 */ | |
| 47 @CalledByNative | |
| 48 public void mediaSessionStateChanged(boolean isControllable, boolean isSuspe nded) {} | |
| 49 | |
| 50 /** | |
| 51 * Called when the native {@link MediaSession} has changed metadata. | |
| 52 * @param metadata The new metadata of the native {@link MediaSession}. "nul l" is for unsetting | |
| 53 * metadata. | |
| 54 */ | |
| 55 @CalledByNative | |
| 56 public void mediaSessionMetadataChanged(MediaMetadata metadata) {} | |
| 57 | |
| 58 /** | |
| 59 * Resume the native {@link MediaSession}. | |
| 60 */ | |
| 61 public final void resumeMediaSession() { | |
| 62 if (hasNativeMediaSession()) nativeResumeMediaSession(mNativeMediaSessio nDelegateAndroid); | |
| 63 } | |
| 64 | |
| 65 /** | |
| 66 * Suspend the native {@link MediaSession}. | |
| 67 */ | |
| 68 public final void suspendMediaSession() { | |
| 69 if (hasNativeMediaSession()) nativeSuspendMediaSession(mNativeMediaSessi onDelegateAndroid); | |
| 70 } | |
| 71 | |
| 72 /** | |
| 73 * Stop the native {@link MediaSession}. | |
| 74 */ | |
| 75 public final void stopMediaSession() { | |
| 76 if (hasNativeMediaSession()) nativeStopMediaSession(mNativeMediaSessionD elegateAndroid); | |
| 77 } | |
| 78 | |
| 79 @CalledByNative | |
| 80 private final void onMediaSessionConnected(long nativeMediaSessionDelegateAn droid) { | |
| 81 mNativeMediaSessionDelegateAndroid = nativeMediaSessionDelegateAndroid; | |
| 82 } | |
| 83 | |
| 84 @CalledByNative | |
| 85 private final void onMediaSessionDisconnected() { | |
| 86 mNativeMediaSessionDelegateAndroid = 0; | |
| 87 mediaSessionDisconnected(); | |
| 88 } | |
| 89 | |
| 90 /** | |
| 91 * @return Whether this {@link MediaSessionDelegate} object is connected to a native | |
| 92 * MediaSession. | |
| 93 */ | |
| 94 private final boolean hasNativeMediaSession() { | |
| 95 return mNativeMediaSessionDelegateAndroid != 0; | |
|
whywhat
2016/10/21 18:28:15
Why do you think any methods of this class can be
| |
| 96 } | |
| 97 | |
| 98 private native void nativeResumeMediaSession(long nativeMediaSessionDelegate Android); | |
| 99 private native void nativeSuspendMediaSession(long nativeMediaSessionDelegat eAndroid); | |
| 100 private native void nativeStopMediaSession(long nativeMediaSessionDelegateAn droid); | |
| 101 private native void nativeDisconnectMediaSession(long nativeMediaSessionDele gateAndroid); | |
| 102 } | |
| OLD | NEW |