Loading core/java/com/android/internal/widget/TransportControlView.java +32 −1 Original line number Diff line number Diff line Loading @@ -35,6 +35,7 @@ import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.os.RemoteException; import android.os.SystemClock; import android.text.Spannable; import android.text.TextUtils; import android.text.style.ForegroundColorSpan; Loading @@ -59,6 +60,7 @@ public class TransportControlView extends FrameLayout implements OnClickListener private static final int MSG_SET_ARTWORK = 103; private static final int MSG_SET_GENERATION_ID = 104; private static final int MAXDIM = 512; private static final int DISPLAY_TIMEOUT_MS = 5000; // 5s protected static final boolean DEBUG = true; protected static final String TAG = "TransportControlView"; Loading Loading @@ -142,7 +144,7 @@ public class TransportControlView extends FrameLayout implements OnClickListener mLocalHandler = new WeakReference<Handler>(handler); } public void setPlaybackState(int generationId, int state) { public void setPlaybackState(int generationId, int state, long stateChangeTimeMs) { Handler handler = mLocalHandler.get(); if (handler != null) { handler.obtainMessage(MSG_UPDATE_STATE, generationId, state).sendToTarget(); Loading Loading @@ -401,4 +403,33 @@ public class TransportControlView extends FrameLayout implements OnClickListener return false; } private boolean wasPlayingRecently(int state, long stateChangeTimeMs) { switch (state) { case RemoteControlClient.PLAYSTATE_PLAYING: case RemoteControlClient.PLAYSTATE_FAST_FORWARDING: case RemoteControlClient.PLAYSTATE_REWINDING: case RemoteControlClient.PLAYSTATE_SKIPPING_FORWARDS: case RemoteControlClient.PLAYSTATE_SKIPPING_BACKWARDS: case RemoteControlClient.PLAYSTATE_BUFFERING: // actively playing or about to play return true; case RemoteControlClient.PLAYSTATE_NONE: return false; case RemoteControlClient.PLAYSTATE_STOPPED: case RemoteControlClient.PLAYSTATE_PAUSED: case RemoteControlClient.PLAYSTATE_ERROR: // we have stopped playing, check how long ago if (DEBUG) { if ((SystemClock.elapsedRealtime() - stateChangeTimeMs) < DISPLAY_TIMEOUT_MS) { Log.v(TAG, "wasPlayingRecently: time < TIMEOUT was playing recently"); } else { Log.v(TAG, "wasPlayingRecently: time > TIMEOUT"); } } return ((SystemClock.elapsedRealtime() - stateChangeTimeMs) < DISPLAY_TIMEOUT_MS); default: Log.e(TAG, "Unknown playback state " + state + " in wasPlayingRecently()"); return false; } } } media/java/android/media/IRemoteControlDisplay.aidl +1 −1 Original line number Diff line number Diff line Loading @@ -40,7 +40,7 @@ oneway interface IRemoteControlDisplay void setCurrentClientId(int clientGeneration, in PendingIntent clientMediaIntent, boolean clearing); void setPlaybackState(int generationId, int state); void setPlaybackState(int generationId, int state, long stateChangeTimeMs); void setTransportControlFlags(int generationId, int transportControlFlags); Loading media/java/android/media/RemoteControlClient.java +17 −6 Original line number Diff line number Diff line Loading @@ -29,6 +29,7 @@ import android.os.Handler; import android.os.Looper; import android.os.Message; import android.os.RemoteException; import android.os.SystemClock; import android.util.Log; import java.lang.IllegalArgumentException; Loading Loading @@ -494,13 +495,17 @@ public class RemoteControlClient */ public void setPlaybackState(int state) { synchronized(mCacheLock) { if (mPlaybackState != state) { // store locally mPlaybackState = state; // keep track of when the state change occurred mPlaybackStateChangeTimeMs = SystemClock.elapsedRealtime(); // send to remote control display if conditions are met sendPlaybackState_syncCacheLock(); } } } /** * Sets the flags for the media transport control buttons that this client supports. Loading Loading @@ -533,6 +538,11 @@ public class RemoteControlClient * Access synchronized on mCacheLock */ private int mPlaybackState = PLAYSTATE_NONE; /** * Time of last play state change * Access synchronized on mCacheLock */ private long mPlaybackStateChangeTimeMs = 0; /** * Cache for the artwork bitmap. * Access synchronized on mCacheLock Loading Loading @@ -716,7 +726,8 @@ public class RemoteControlClient private void sendPlaybackState_syncCacheLock() { if ((mCurrentClientGenId == mInternalClientGenId) && (mRcDisplay != null)) { try { mRcDisplay.setPlaybackState(mInternalClientGenId, mPlaybackState); mRcDisplay.setPlaybackState(mInternalClientGenId, mPlaybackState, mPlaybackStateChangeTimeMs); } catch (RemoteException e) { Log.e(TAG, "Error in setPlaybackState(), dead display "+e); detachFromDisplay_syncCacheLock(); Loading Loading
core/java/com/android/internal/widget/TransportControlView.java +32 −1 Original line number Diff line number Diff line Loading @@ -35,6 +35,7 @@ import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.os.RemoteException; import android.os.SystemClock; import android.text.Spannable; import android.text.TextUtils; import android.text.style.ForegroundColorSpan; Loading @@ -59,6 +60,7 @@ public class TransportControlView extends FrameLayout implements OnClickListener private static final int MSG_SET_ARTWORK = 103; private static final int MSG_SET_GENERATION_ID = 104; private static final int MAXDIM = 512; private static final int DISPLAY_TIMEOUT_MS = 5000; // 5s protected static final boolean DEBUG = true; protected static final String TAG = "TransportControlView"; Loading Loading @@ -142,7 +144,7 @@ public class TransportControlView extends FrameLayout implements OnClickListener mLocalHandler = new WeakReference<Handler>(handler); } public void setPlaybackState(int generationId, int state) { public void setPlaybackState(int generationId, int state, long stateChangeTimeMs) { Handler handler = mLocalHandler.get(); if (handler != null) { handler.obtainMessage(MSG_UPDATE_STATE, generationId, state).sendToTarget(); Loading Loading @@ -401,4 +403,33 @@ public class TransportControlView extends FrameLayout implements OnClickListener return false; } private boolean wasPlayingRecently(int state, long stateChangeTimeMs) { switch (state) { case RemoteControlClient.PLAYSTATE_PLAYING: case RemoteControlClient.PLAYSTATE_FAST_FORWARDING: case RemoteControlClient.PLAYSTATE_REWINDING: case RemoteControlClient.PLAYSTATE_SKIPPING_FORWARDS: case RemoteControlClient.PLAYSTATE_SKIPPING_BACKWARDS: case RemoteControlClient.PLAYSTATE_BUFFERING: // actively playing or about to play return true; case RemoteControlClient.PLAYSTATE_NONE: return false; case RemoteControlClient.PLAYSTATE_STOPPED: case RemoteControlClient.PLAYSTATE_PAUSED: case RemoteControlClient.PLAYSTATE_ERROR: // we have stopped playing, check how long ago if (DEBUG) { if ((SystemClock.elapsedRealtime() - stateChangeTimeMs) < DISPLAY_TIMEOUT_MS) { Log.v(TAG, "wasPlayingRecently: time < TIMEOUT was playing recently"); } else { Log.v(TAG, "wasPlayingRecently: time > TIMEOUT"); } } return ((SystemClock.elapsedRealtime() - stateChangeTimeMs) < DISPLAY_TIMEOUT_MS); default: Log.e(TAG, "Unknown playback state " + state + " in wasPlayingRecently()"); return false; } } }
media/java/android/media/IRemoteControlDisplay.aidl +1 −1 Original line number Diff line number Diff line Loading @@ -40,7 +40,7 @@ oneway interface IRemoteControlDisplay void setCurrentClientId(int clientGeneration, in PendingIntent clientMediaIntent, boolean clearing); void setPlaybackState(int generationId, int state); void setPlaybackState(int generationId, int state, long stateChangeTimeMs); void setTransportControlFlags(int generationId, int transportControlFlags); Loading
media/java/android/media/RemoteControlClient.java +17 −6 Original line number Diff line number Diff line Loading @@ -29,6 +29,7 @@ import android.os.Handler; import android.os.Looper; import android.os.Message; import android.os.RemoteException; import android.os.SystemClock; import android.util.Log; import java.lang.IllegalArgumentException; Loading Loading @@ -494,13 +495,17 @@ public class RemoteControlClient */ public void setPlaybackState(int state) { synchronized(mCacheLock) { if (mPlaybackState != state) { // store locally mPlaybackState = state; // keep track of when the state change occurred mPlaybackStateChangeTimeMs = SystemClock.elapsedRealtime(); // send to remote control display if conditions are met sendPlaybackState_syncCacheLock(); } } } /** * Sets the flags for the media transport control buttons that this client supports. Loading Loading @@ -533,6 +538,11 @@ public class RemoteControlClient * Access synchronized on mCacheLock */ private int mPlaybackState = PLAYSTATE_NONE; /** * Time of last play state change * Access synchronized on mCacheLock */ private long mPlaybackStateChangeTimeMs = 0; /** * Cache for the artwork bitmap. * Access synchronized on mCacheLock Loading Loading @@ -716,7 +726,8 @@ public class RemoteControlClient private void sendPlaybackState_syncCacheLock() { if ((mCurrentClientGenId == mInternalClientGenId) && (mRcDisplay != null)) { try { mRcDisplay.setPlaybackState(mInternalClientGenId, mPlaybackState); mRcDisplay.setPlaybackState(mInternalClientGenId, mPlaybackState, mPlaybackStateChangeTimeMs); } catch (RemoteException e) { Log.e(TAG, "Error in setPlaybackState(), dead display "+e); detachFromDisplay_syncCacheLock(); Loading