4

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:

  1. 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 in MusicService.getAvailableActions().
  2. Change the line to actions |= PlaybackState.ACTION_STOP, run the app, hit PLAY, and a STOP button appears, as is expected.
  3. Change the value back to actions |= PlaybackState.ACTION_PAUSE, run the app, hit PLAY, and a STOP button appears, an unexpected behavior.
  4. 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:

  1. Clear the app data: Settings -> Apps -> Media Browser Service Simulator -> Clear Data
  2. 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.

Jason Hartley
  • 2,459
  • 1
  • 31
  • 40
  • Setting the action to `PlaybackState.ACTION_PLAY_PAUSE` seemed like it would be a step in the right direction, but still didn't display a pause button. – Jason Hartley Mar 13 '15 at 14:30
  • Can you please specify whether you're seeing the stop button on the auto simulator or in an app? Also can you post your code which shows the mediaSession setup as well your code in MediaSessionCallback.onPlay(..) – Nagesh Susarla Mar 14 '15 at 05:55
  • @NageshSusarla, it appears to be a bug with the simulator, both when running in an emulator or on a physical device. Please see my update above. – Jason Hartley Mar 16 '15 at 05:07
  • Thanks, I'll take a look at the simulator code and keep you posted. – Nagesh Susarla Mar 16 '15 at 05:15
  • @NageshSusarla were you able to confirm that this is a bug? Should I file a bug report? – Jason Hartley Mar 18 '15 at 19:29
  • Yes there is indeed some oddity but restarting the simulator seems to fix it for me. You can definitely file a bug for this! Thanks – Nagesh Susarla Mar 19 '15 at 23:25

0 Answers0