Search code examples
androidaudioandroid-mediaplayerandroid-audiomanagerandroid-auto

Android Auto Audio Playback - buttons not seen


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?


Solution

  • 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.