Commit d2655218 authored by aberent's avatar aberent Committed by Commit bot

Re-enable volume control for Android Cast

Previously this was enabled through the (lock screen)
RemoteControlClient, but this was removed in
https://codereview.chromium.org/1652163002/. Reenable
it through the notification's MediaSessionCompat.

BUG=585393

Review URL: https://codereview.chromium.org/1679923005

Cr-Commit-Position: refs/heads/master@{#374729}
parent c607f296
...@@ -23,6 +23,7 @@ import android.support.v4.app.NotificationManagerCompat; ...@@ -23,6 +23,7 @@ import android.support.v4.app.NotificationManagerCompat;
import android.support.v4.media.MediaMetadataCompat; import android.support.v4.media.MediaMetadataCompat;
import android.support.v4.media.session.MediaSessionCompat; import android.support.v4.media.session.MediaSessionCompat;
import android.support.v4.media.session.PlaybackStateCompat; import android.support.v4.media.session.PlaybackStateCompat;
import android.support.v7.media.MediaRouter;
import android.util.SparseArray; import android.util.SparseArray;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.View; import android.view.View;
...@@ -599,9 +600,20 @@ public class MediaNotificationManager { ...@@ -599,9 +600,20 @@ public class MediaNotificationManager {
mMediaNotificationInfo.isPrivate ? NotificationCompat.VISIBILITY_PRIVATE mMediaNotificationInfo.isPrivate ? NotificationCompat.VISIBILITY_PRIVATE
: NotificationCompat.VISIBILITY_PUBLIC); : NotificationCompat.VISIBILITY_PUBLIC);
if (mMediaNotificationInfo.supportsPlayPause()) { if (mMediaNotificationInfo.supportsPlayPause()) {
if (mMediaSession == null) mMediaSession = createMediaSession();
if (mMediaSession == null) mMediaSession = createMediaSession();
try {
// Tell the MediaRouter about the session, so that Chrome can control the volume
// on the remote cast device (if any).
// Pre-MR1 versions of JB do not have the complete MediaRouter APIs,
// so getting the MediaRouter instance will throw an exception.
MediaRouter.getInstance(mContext).setMediaSessionCompat(mMediaSession);
} catch (NoSuchMethodError e) {
// Do nothing. Chrome can't be casting without a MediaRouter, so there is nothing
// to do here.
}
mMediaSession.setMetadata(createMetadata()); mMediaSession.setMetadata(createMetadata());
PlaybackStateCompat.Builder playbackStateBuilder = new PlaybackStateCompat.Builder() PlaybackStateCompat.Builder playbackStateBuilder = new PlaybackStateCompat.Builder()
...@@ -610,7 +622,6 @@ public class MediaNotificationManager { ...@@ -610,7 +622,6 @@ public class MediaNotificationManager {
playbackStateBuilder.setState(PlaybackStateCompat.STATE_PAUSED, playbackStateBuilder.setState(PlaybackStateCompat.STATE_PAUSED,
PlaybackStateCompat.PLAYBACK_POSITION_UNKNOWN, 1.0f); PlaybackStateCompat.PLAYBACK_POSITION_UNKNOWN, 1.0f);
} else { } else {
// If notification only supports stop, still pretend
playbackStateBuilder.setState(PlaybackStateCompat.STATE_PLAYING, playbackStateBuilder.setState(PlaybackStateCompat.STATE_PLAYING,
PlaybackStateCompat.PLAYBACK_POSITION_UNKNOWN, 1.0f); PlaybackStateCompat.PLAYBACK_POSITION_UNKNOWN, 1.0f);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment