diff options
author | RoboErik <epastern@google.com> | 2014-07-09 15:05:53 -0700 |
---|---|---|
committer | RoboErik <epastern@google.com> | 2014-07-14 11:17:06 -0700 |
commit | 550116576cce028d3c435f7c3ae9f6e3b92b5cf2 (patch) | |
tree | ca7bf5f9f2564ea6a34c37d94216e7f531236772 /tests/OneMedia/src | |
parent | a4ab780877808dbee334f7c7cc4acefa0aa313b2 (diff) | |
download | frameworks_base-550116576cce028d3c435f7c3ae9f6e3b92b5cf2.zip frameworks_base-550116576cce028d3c435f7c3ae9f6e3b92b5cf2.tar.gz frameworks_base-550116576cce028d3c435f7c3ae9f6e3b92b5cf2.tar.bz2 |
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
Diffstat (limited to 'tests/OneMedia/src')
-rw-r--r-- | tests/OneMedia/src/com/android/onemedia/PlayerController.java | 12 |
1 files changed, 9 insertions, 3 deletions
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"); |