From 7c700e80b902c8f7778ffd63c287ac5710fd69ef Mon Sep 17 00:00:00 2001 From: Renato Mangini Date: Wed, 8 Oct 2014 18:32:55 -0700 Subject: Add slot reservation to Gearhead music sample. Also add SmallIcon metadata. B=17924045 Change-Id: I145d02efc871af5df4033053fab9375238fb93eb --- MusicDemo/src/main/AndroidManifest.xml | 9 ++++++++- .../android/musicservicedemo/MusicService.java | 19 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) (limited to 'MusicDemo') diff --git a/MusicDemo/src/main/AndroidManifest.xml b/MusicDemo/src/main/AndroidManifest.xml index 608dbc5..f84ee42 100644 --- a/MusicDemo/src/main/AndroidManifest.xml +++ b/MusicDemo/src/main/AndroidManifest.xml @@ -35,6 +35,13 @@ + + + - \ No newline at end of file + diff --git a/MusicDemo/src/main/java/com/example/android/musicservicedemo/MusicService.java b/MusicDemo/src/main/java/com/example/android/musicservicedemo/MusicService.java index f7e9dfc..1950cd6 100644 --- a/MusicDemo/src/main/java/com/example/android/musicservicedemo/MusicService.java +++ b/MusicDemo/src/main/java/com/example/android/musicservicedemo/MusicService.java @@ -166,6 +166,7 @@ public class MusicService extends MediaBrowserService implements OnPreparedListe mWifiLock = ((WifiManager) getSystemService(Context.WIFI_SERVICE)) .createWifiLock(WifiManager.WIFI_MODE_FULL, "MusicDemo_lock"); + // Create the music catalog metadata provider mMusicProvider = new MusicProvider(); mMusicProvider.retrieveMedia(new MusicProvider.Callback() { @@ -183,6 +184,23 @@ public class MusicService extends MediaBrowserService implements OnPreparedListe mSession.setCallback(new MediaSessionCallback()); mSession.setFlags(MediaSession.FLAG_HANDLES_MEDIA_BUTTONS | MediaSession.FLAG_HANDLES_TRANSPORT_CONTROLS); + + // Use these extras to reserve space for the corresponding actions, even when they are disabled + // in the playbackstate, so the custom actions don't reflow. + Bundle extras = new Bundle(); + extras.putBoolean( + "com.google.android.gms.car.media.ALWAYS_RESERVE_SPACE_FOR.ACTION_SKIP_TO_NEXT", + true); + extras.putBoolean( + "com.google.android.gms.car.media.ALWAYS_RESERVE_SPACE_FOR.ACTION_SKIP_TO_PREVIOUS", + true); + // If you want to reserve the Queue slot when there is no queue + // (mSession.setQueue(emptylist)), uncomment the lines below: + // extras.putBoolean( + // "com.google.android.gms.car.media.ALWAYS_RESERVE_SPACE_FOR.ACTION_QUEUE", + // true); + mSession.setExtras(extras); + updatePlaybackState(null); mMediaNotification = new MediaNotification(this); @@ -771,6 +789,7 @@ public class MusicService extends MediaBrowserService implements OnPreparedListe * */ private void updatePlaybackState(String error) { + LogHelper.d(TAG, "updatePlaybackState, setting session playback state to " + mState); long position = PlaybackState.PLAYBACK_POSITION_UNKNOWN; if (mMediaPlayer != null && mMediaPlayer.isPlaying()) { -- cgit v1.2.3