From 477d1197c3c25c01ace7ea4494437c23720a2eb3 Mon Sep 17 00:00:00 2001 From: RoboErik Date: Wed, 6 Aug 2014 13:43:22 -0700 Subject: Combine MediaSession Callback and TransportControlsCallback This combines them into a single Callback class and adds default handling to media buttons to check the available actions and call one of the other methods if appropriate. Change-Id: If9897d8cf6d8d8046aa85a646c22382f1db1461b --- .../src/com/android/onemedia/PlayerSession.java | 28 ++++------------------ 1 file changed, 4 insertions(+), 24 deletions(-) (limited to 'tests/OneMedia') diff --git a/tests/OneMedia/src/com/android/onemedia/PlayerSession.java b/tests/OneMedia/src/com/android/onemedia/PlayerSession.java index feecfde..890d68d 100644 --- a/tests/OneMedia/src/com/android/onemedia/PlayerSession.java +++ b/tests/OneMedia/src/com/android/onemedia/PlayerSession.java @@ -86,10 +86,10 @@ public class PlayerSession { mRouter.setRoutingCallback(new RoutingCallback(), null); mSession = new MediaSession(mContext, "OneMedia"); - mSession.addCallback(mCallback); - mSession.addTransportControlsCallback(new TransportCallback()); + mSession.setCallback(mCallback); mSession.setPlaybackState(mPlaybackState); - mSession.setFlags(MediaSession.FLAG_HANDLES_TRANSPORT_CONTROLS); + mSession.setFlags(MediaSession.FLAG_HANDLES_TRANSPORT_CONTROLS + | MediaSession.FLAG_HANDLES_MEDIA_BUTTONS); mSession.setMediaRouter(mRouter); mSession.setActive(true); } @@ -230,26 +230,6 @@ public class PlayerSession { private class SessionCb extends MediaSession.Callback { @Override - public void onMediaButtonEvent(Intent mediaRequestIntent) { - if (Intent.ACTION_MEDIA_BUTTON.equals(mediaRequestIntent.getAction())) { - KeyEvent event = (KeyEvent) mediaRequestIntent - .getParcelableExtra(Intent.EXTRA_KEY_EVENT); - switch (event.getKeyCode()) { - case KeyEvent.KEYCODE_MEDIA_PLAY: - Log.d(TAG, "play button received"); - mRenderer.onPlay(); - break; - case KeyEvent.KEYCODE_MEDIA_PAUSE: - Log.d(TAG, "pause button received"); - mRenderer.onPause(); - break; - } - } - } - } - - private class TransportCallback extends MediaSession.TransportControlsCallback { - @Override public void onPlay() { mRenderer.onPlay(); } @@ -315,7 +295,7 @@ public class PlayerSession { updateState(PlaybackState.STATE_NONE); break; } - } + } } } } -- cgit v1.1