From f1372428f2df781c71c71caa2f6a4db6f847cf10 Mon Sep 17 00:00:00 2001 From: RoboErik Date: Wed, 23 Apr 2014 14:38:17 -0700 Subject: Add Session API calls to RCC and AudioManager This makes RCC and MediaButtonReceiver (via AudioManager) also use the new Session APIs in parallel to their existing code. This will allow us to bring up the Session compatibility pieces without disrupting the old behavior and then switch everything over to just using the new APIs when ready. Change-Id: I33ce0a044dea3ec763f2302b91a5e415be27d4a4 --- .../src/com/android/onemedia/PlayerSession.java | 31 +++++++++++----------- .../onemedia/provider/OneMediaRouteProvider.java | 21 ++++++++------- 2 files changed, 28 insertions(+), 24 deletions(-) (limited to 'tests') diff --git a/tests/OneMedia/src/com/android/onemedia/PlayerSession.java b/tests/OneMedia/src/com/android/onemedia/PlayerSession.java index 5dc3904..2e029f0 100644 --- a/tests/OneMedia/src/com/android/onemedia/PlayerSession.java +++ b/tests/OneMedia/src/com/android/onemedia/PlayerSession.java @@ -119,7 +119,9 @@ public class PlayerSession { } private void updateState(int newState) { - mPlaybackState.setState(newState); + float rate = newState == PlaybackState.PLAYSTATE_PLAYING ? 1 : 0; + long position = mRenderer == null ? -1 : mRenderer.getSeekPosition(); + mPlaybackState.setState(newState, position, rate); mPerformer.setPlaybackState(mPlaybackState); } @@ -132,7 +134,7 @@ public class PlayerSession { @Override public void onError(int type, int extra, Bundle extras, Throwable error) { Log.d(TAG, "Sending onError with type " + type + " and extra " + extra); - mPlaybackState.setState(PlaybackState.PLAYSTATE_ERROR); + mPlaybackState.setState(PlaybackState.PLAYSTATE_ERROR, -1, 0); if (error != null) { mPlaybackState.setErrorMessage(error.getLocalizedMessage()); } @@ -147,34 +149,33 @@ public class PlayerSession { if (newState != Renderer.STATE_ERROR) { mPlaybackState.setErrorMessage(null); } + long position = -1; + if (mRenderer != null) { + position = mRenderer.getSeekPosition(); + } switch (newState) { case Renderer.STATE_ENDED: case Renderer.STATE_STOPPED: - mPlaybackState.setState(PlaybackState.PLAYSTATE_STOPPED); + mPlaybackState.setState(PlaybackState.PLAYSTATE_STOPPED, position, 0); break; case Renderer.STATE_INIT: case Renderer.STATE_PREPARING: - mPlaybackState.setState(PlaybackState.PLAYSTATE_BUFFERING); + mPlaybackState.setState(PlaybackState.PLAYSTATE_BUFFERING, position, 0); break; case Renderer.STATE_ERROR: - mPlaybackState.setState(PlaybackState.PLAYSTATE_ERROR); + mPlaybackState.setState(PlaybackState.PLAYSTATE_ERROR, position, 0); break; case Renderer.STATE_PAUSED: - mPlaybackState.setState(PlaybackState.PLAYSTATE_PAUSED); + mPlaybackState.setState(PlaybackState.PLAYSTATE_PAUSED, position, 0); break; case Renderer.STATE_PLAYING: - mPlaybackState.setState(PlaybackState.PLAYSTATE_PLAYING); + mPlaybackState.setState(PlaybackState.PLAYSTATE_PLAYING, position, 1); break; default: - mPlaybackState.setState(PlaybackState.PLAYSTATE_ERROR); + mPlaybackState.setState(PlaybackState.PLAYSTATE_ERROR, position, 0); mPlaybackState.setErrorMessage("unkown state"); break; } - if (mRenderer != null) { - mPlaybackState.setPosition(mRenderer.getSeekPosition()); - } else { - mPlaybackState.setPosition(-1); - } mPerformer.setPlaybackState(mPlaybackState); if (mListener != null) { mListener.onPlayStateChanged(mPlaybackState); @@ -188,8 +189,8 @@ public class PlayerSession { @Override public void onFocusLost() { Log.d(TAG, "Focus lost, changing state to " + Renderer.STATE_PAUSED); - mPlaybackState.setState(PlaybackState.PLAYSTATE_PAUSED); - mPlaybackState.setPosition(mRenderer.getSeekPosition()); + long position = mRenderer == null ? -1 : mRenderer.getSeekPosition(); + mPlaybackState.setState(PlaybackState.PLAYSTATE_PAUSED, position, 0); mPerformer.setPlaybackState(mPlaybackState); if (mListener != null) { mListener.onPlayStateChanged(mPlaybackState); diff --git a/tests/OneMedia/src/com/android/onemedia/provider/OneMediaRouteProvider.java b/tests/OneMedia/src/com/android/onemedia/provider/OneMediaRouteProvider.java index 6edcd7d..6537d49 100644 --- a/tests/OneMedia/src/com/android/onemedia/provider/OneMediaRouteProvider.java +++ b/tests/OneMedia/src/com/android/onemedia/provider/OneMediaRouteProvider.java @@ -158,30 +158,33 @@ public class OneMediaRouteProvider extends RouteProviderService { if (newState != Renderer.STATE_ERROR) { mPlaybackState.setErrorMessage(null); } + long position = -1; + if (mRenderer != null) { + position = mRenderer.getSeekPosition(); + } switch (newState) { case Renderer.STATE_ENDED: case Renderer.STATE_STOPPED: - mPlaybackState.setState(PlaybackState.PLAYSTATE_STOPPED); + mPlaybackState.setState(PlaybackState.PLAYSTATE_STOPPED, position, 0); break; case Renderer.STATE_INIT: case Renderer.STATE_PREPARING: - mPlaybackState.setState(PlaybackState.PLAYSTATE_BUFFERING); + mPlaybackState.setState(PlaybackState.PLAYSTATE_BUFFERING, position, 0); break; case Renderer.STATE_ERROR: - mPlaybackState.setState(PlaybackState.PLAYSTATE_ERROR); + mPlaybackState.setState(PlaybackState.PLAYSTATE_ERROR, position, 0); break; case Renderer.STATE_PAUSED: - mPlaybackState.setState(PlaybackState.PLAYSTATE_PAUSED); + mPlaybackState.setState(PlaybackState.PLAYSTATE_PAUSED, position, 0); break; case Renderer.STATE_PLAYING: - mPlaybackState.setState(PlaybackState.PLAYSTATE_PLAYING); + mPlaybackState.setState(PlaybackState.PLAYSTATE_PLAYING, position, 1); break; default: - mPlaybackState.setState(PlaybackState.PLAYSTATE_ERROR); + mPlaybackState.setState(PlaybackState.PLAYSTATE_ERROR, position, 0); mPlaybackState.setErrorMessage("unkown state"); break; } - mPlaybackState.setPosition(mRenderer.getSeekPosition()); mControls.sendPlaybackChangeEvent(mPlaybackState.getState()); } @@ -193,8 +196,8 @@ public class OneMediaRouteProvider extends RouteProviderService { @Override public void onFocusLost() { Log.d(TAG, "Focus lost, changing state to " + Renderer.STATE_PAUSED); - mPlaybackState.setState(PlaybackState.PLAYSTATE_PAUSED); - mPlaybackState.setPosition(mRenderer.getSeekPosition()); + mPlaybackState.setState(PlaybackState.PLAYSTATE_PAUSED, mRenderer.getSeekPosition(), 0); + mRenderer.onPause(); } @Override -- cgit v1.1