| Index: content/public/android/java/src/org/chromium/content/browser/MediaSessionDelegate.java
|
| diff --git a/content/public/android/java/src/org/chromium/content/browser/MediaSession.java b/content/public/android/java/src/org/chromium/content/browser/MediaSessionDelegate.java
|
| similarity index 53%
|
| rename from content/public/android/java/src/org/chromium/content/browser/MediaSession.java
|
| rename to content/public/android/java/src/org/chromium/content/browser/MediaSessionDelegate.java
|
| index 6723de74e8429d215b7db66138fc6844f2122bf0..df16ecb84d589596289ce239baf0588b8415e466 100644
|
| --- a/content/public/android/java/src/org/chromium/content/browser/MediaSession.java
|
| +++ b/content/public/android/java/src/org/chromium/content/browser/MediaSessionDelegate.java
|
| @@ -12,18 +12,19 @@ import org.chromium.base.annotations.CalledByNative;
|
| import org.chromium.base.annotations.JNINamespace;
|
|
|
| /**
|
| - * MediaSession is the Java counterpart of content::MediaSession.
|
| - * It is being used to communicate from content::MediaSession (C++) to the
|
| - * Android system. A MediaSession is implementing OnAudioFocusChangeListener,
|
| - * making it an audio focus holder for Android. Thus two instances of
|
| - * MediaSession can't have audio focus at the same time.
|
| - * A MediaSession will use the type requested from its C++ counterpart and will
|
| - * resume its play using the same type if it were to happen, for example, when
|
| - * it got temporarily suspended by a transient sound like a notification.
|
| + * MediaSession is the Java counterpart of content::MediaSessionDelegateAndroid.
|
| + * It is being used to communicate from content::MediaSessionDelegateAndroid
|
| + * (C++) to the Android system. A MediaSessionDelegate is implementingf
|
| + * OnAudioFocusChangeListener, making it an audio focus holder for Android. Thus
|
| + * two instances of MediaSessionDelegate can't have audio focus at the same
|
| + * time. A MediaSessionDelegate will use the type requested from its C++
|
| + * counterpart and will resume its play using the same type if it were to
|
| + * happen, for example, when it got temporarily suspended by a transient sound
|
| + * like a notification.
|
| */
|
| @JNINamespace("content")
|
| -public class MediaSession implements AudioManager.OnAudioFocusChangeListener {
|
| - private static final String TAG = "cr.MediaSession";
|
| +public class MediaSessionDelegate implements AudioManager.OnAudioFocusChangeListener {
|
| + private static final String TAG = "MediaSession";
|
|
|
| // These need to match the values in native apps.
|
| public static final double DUCKING_VOLUME_MULTIPLIER = 0.2f;
|
| @@ -33,17 +34,18 @@ public class MediaSession implements AudioManager.OnAudioFocusChangeListener {
|
| private int mFocusType;
|
| private boolean mIsDucking = false;
|
|
|
| - // Native pointer to C++ content::MediaSession.
|
| - private final long mNativeMediaSession;
|
| + // Native pointer to C++ content::MediaSessionAndroid.
|
| + private final long mNativeMediaSessionDelegateAndroid;
|
|
|
| - private MediaSession(final Context context, long nativeMediaSession) {
|
| + private MediaSessionDelegate(final Context context, long nativeMediaSessionDelegateAndroid) {
|
| mContext = context;
|
| - mNativeMediaSession = nativeMediaSession;
|
| + mNativeMediaSessionDelegateAndroid = nativeMediaSessionDelegateAndroid;
|
| }
|
|
|
| @CalledByNative
|
| - private static MediaSession createMediaSession(Context context, long nativeMediaSession) {
|
| - return new MediaSession(context, nativeMediaSession);
|
| + private static MediaSessionDelegate create(Context context,
|
| + long nativeMediaSessionDelegateAndroid) {
|
| + return new MediaSessionDelegate(context, nativeMediaSessionDelegateAndroid);
|
| }
|
|
|
| @CalledByNative
|
| @@ -71,23 +73,25 @@ public class MediaSession implements AudioManager.OnAudioFocusChangeListener {
|
| switch (focusChange) {
|
| case AudioManager.AUDIOFOCUS_GAIN:
|
| if (mIsDucking) {
|
| - nativeOnSetVolumeMultiplier(mNativeMediaSession, DEFAULT_VOLUME_MULTIPLIER);
|
| + nativeOnSetVolumeMultiplier(mNativeMediaSessionDelegateAndroid,
|
| + DEFAULT_VOLUME_MULTIPLIER);
|
| mIsDucking = false;
|
| } else {
|
| - nativeOnResume(mNativeMediaSession);
|
| + nativeOnResume(mNativeMediaSessionDelegateAndroid);
|
| }
|
| break;
|
| case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
|
| - nativeOnSuspend(mNativeMediaSession, true);
|
| + nativeOnSuspend(mNativeMediaSessionDelegateAndroid, true);
|
| break;
|
| case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK:
|
| mIsDucking = true;
|
| - nativeRecordSessionDuck(mNativeMediaSession);
|
| - nativeOnSetVolumeMultiplier(mNativeMediaSession, DUCKING_VOLUME_MULTIPLIER);
|
| + nativeRecordSessionDuck(mNativeMediaSessionDelegateAndroid);
|
| + nativeOnSetVolumeMultiplier(mNativeMediaSessionDelegateAndroid,
|
| + DUCKING_VOLUME_MULTIPLIER);
|
| break;
|
| case AudioManager.AUDIOFOCUS_LOSS:
|
| abandonAudioFocus();
|
| - nativeOnSuspend(mNativeMediaSession, false);
|
| + nativeOnSuspend(mNativeMediaSessionDelegateAndroid, false);
|
| break;
|
| default:
|
| Log.w(TAG, "onAudioFocusChange called with unexpected value %d", focusChange);
|
| @@ -95,9 +99,9 @@ public class MediaSession implements AudioManager.OnAudioFocusChangeListener {
|
| }
|
| }
|
|
|
| - private native void nativeOnSuspend(long nativeMediaSession, boolean temporary);
|
| - private native void nativeOnResume(long nativeMediaSession);
|
| - private native void nativeOnSetVolumeMultiplier(
|
| - long nativeMediaSession, double volumeMultiplier);
|
| - private native void nativeRecordSessionDuck(long nativeMediaSession);
|
| + private native void nativeOnSuspend(long nativeMediaSessionDelegateAndroid, boolean temporary);
|
| + private native void nativeOnResume(long nativeMediaSessionDelegateAndroid);
|
| + private native void nativeOnSetVolumeMultiplier(long nativeMediaSessionDelegateAndroid,
|
| + double volumeMultiplier);
|
| + private native void nativeRecordSessionDuck(long nativeMediaSessionDelegateAndroid);
|
| }
|
|
|