From 550116576cce028d3c435f7c3ae9f6e3b92b5cf2 Mon Sep 17 00:00:00 2001 From: RoboErik Date: Wed, 9 Jul 2014 15:05:53 -0700 Subject: Add API to set a default session in Activity We may have multiple remote sessions at once so an app needs a way to specify a default session to route media and volume commands to when its activity is in the foreground. This adds an api that works in parallel with the default stream api on Activity. bug:15727927 Change-Id: I5b67cb3e20647f9437d90aa65be63efe8c7865cf --- .../OneMedia/src/com/android/onemedia/PlayerController.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'tests/OneMedia/src') diff --git a/tests/OneMedia/src/com/android/onemedia/PlayerController.java b/tests/OneMedia/src/com/android/onemedia/PlayerController.java index 802f473..9cbb455 100644 --- a/tests/OneMedia/src/com/android/onemedia/PlayerController.java +++ b/tests/OneMedia/src/com/android/onemedia/PlayerController.java @@ -18,12 +18,14 @@ package com.android.onemedia; import android.media.MediaMetadata; import android.media.session.MediaController; +import android.media.session.MediaSession; import android.media.session.MediaSessionManager; import android.media.session.PlaybackState; import android.os.Bundle; import android.os.Handler; import android.os.IBinder; import android.os.RemoteException; +import android.app.Activity; import android.content.ComponentName; import android.content.Context; import android.content.Intent; @@ -43,7 +45,7 @@ public class PlayerController { protected MediaController.TransportControls mTransportControls; private final Intent mServiceIntent; - private Context mContext; + private Activity mContext; private Listener mListener; private SessionCallback mControllerCb; private MediaSessionManager mManager; @@ -51,7 +53,7 @@ public class PlayerController { private boolean mResumed; - public PlayerController(Context context, Intent serviceIntent) { + public PlayerController(Activity context, Intent serviceIntent) { mContext = context; if (serviceIntent == null) { mServiceIntent = new Intent(mContext, PlayerService.class); @@ -140,6 +142,7 @@ public class PlayerController { mBinder = null; mController = null; mTransportControls = null; + mContext.setMediaController(null); Log.d(TAG, "Disconnected from PlayerService"); if (mListener != null) { @@ -151,12 +154,15 @@ public class PlayerController { public void onServiceConnected(ComponentName name, IBinder service) { mBinder = IPlayerService.Stub.asInterface(service); Log.d(TAG, "service is " + service + " binder is " + mBinder); + MediaSession.Token token; try { - mController = MediaController.fromToken(mBinder.getSessionToken()); + token = mBinder.getSessionToken(); } catch (RemoteException e) { Log.e(TAG, "Error getting session", e); return; } + mController = MediaController.fromToken(token); + mContext.setMediaController(mController); mController.addCallback(mControllerCb, mHandler); mTransportControls = mController.getTransportControls(); Log.d(TAG, "Ready to use PlayerService"); -- cgit v1.1