1

I am writing an app that supports audio playback on Android Auto, by extending MediaBrowserService, as described in the documentation. My code works perfectly fine in the Android Auto Media simulator, but in an actual car, the playback control buttons are not seen. I am still able to play an audio file by selecting it from the list of files; but I can't pause/play or go to next/previous etc.

Anyone else has seen this problem? Any suggestions?

Chaitanya
  • 2,039
  • 4
  • 25
  • 32

1 Answers1

2

Turns out we do not get buttons "by default" as I had assumed, looking at the Simulator. We have to set the PlaybackState for the MediaSession. This is where we can specify the available actions, and change them as needed - for example, show the 'skip to next' button only when we have more tracks to play.

A good way to figure out if you have got this working using simulator is to try the Hardware Controls from simulator overflow menu. For me, the visible playback buttons in the simulator were always working, but the hardware controls started working only after I started to set the playback state.

A good reference is the MusicService class in the MediaBrowserService sample. They have code that manipulates the playback state in there.

Chaitanya
  • 2,039
  • 4
  • 25
  • 32
  • I'm also starting from MediaBrowserService sample, but wanted to add also "Rewind" and "Fast Forward" buttons. I set the correct flags in PlaybackState: actions |= PlaybackState.ACTION_FAST_FORWARD | PlaybackState.ACTION_REWIND; but they never show up. Did you every try this as well? I'd like also to hide the button with a list and music note at left (is this the recently played list or something?), no idea how... – gregko Oct 12 '15 at 23:50
  • I haven't tried rewind and fast-forward, sorry. My use-case doesn't need these. – Chaitanya Oct 16 '15 at 23:17
  • Thank you, no problem, I figured out a way of doing what I need with custom controls. – gregko Oct 17 '15 at 00:14
  • 2
    @gregko can you please provide more detail about adding those fast_forward/rewind buttons? I cannot figure out hos to do so. – user1026605 Aug 25 '17 at 22:04