How can I control when a Stop button vs. Pause button is displayed in the "Media control card" while playing audio in an Android Auto Media app?
I'm setting the actions in a PlaybackState
object, then setting that in my MediaSession
object like so (this is a very abridged example):
PlaybackState.Builder playbackState = new PlaybackState.Builder();
playbackState.setActions(PlaybackState.ACTION_PAUSE).build();
mMediaSession.setPlaybackState(playbackState);
I realize the actions value is a bit mask for a various combinations of actions, but no matter what I put in setActions
I get a stop button.
UPDATE: It appears to be a bug with Google's Media Browser Service Simulator. A workaround is to clear the app's data by selecting Settings -> Apps -> Media Browser Service Simulator -> Clear Data before running your app again. I am using version 6.5.81 (1593596-030) of the simulator. I also am experiencing this bug running the simulator on a physical Nexus 7.
Steps to reproduce:
- Run Google's sample app, Universal Music Player, hit PLAY, and a PAUSE button
appears, as is expected because
actions |= PlaybackState.ACTION_PAUSE
is set inMusicService.getAvailableActions()
. - Change the line to
actions |= PlaybackState.ACTION_STOP
, run the app, hit PLAY, and a STOP button appears, as is expected. - Change the value back to
actions |= PlaybackState.ACTION_PAUSE
, run the app, hit PLAY, and a STOP button appears, an unexpected behavior. - You can confirm through debugging that
actions
contains the bit mask value for PAUSE and not STOP.
Note: Although the square STOP button is displayed, the button's behavior is PAUSE.
Workaround:
- Clear the app data: Settings -> Apps -> Media Browser Service Simulator -> Clear Data
- Run the Universal Music Player app again in the simulator, hit PLAY, and the PAUSE button appears, as expected.
UPDATE #2: It seems that once the STOP button has appeared, the PAUSE button can never appear again, and this workaround is not useful.