article

Amelia@Amazon avatar image
Amelia@Amazon posted

Replacing RemoteControlClient with MediaSession's Media Controls   

Summary

From Android 5.0(API Level 21), RemoteControlClient API which was often used for media transport controls to the lockscreen has been deprecated. Media transport control buttons won't be shown on the lock screen with RemoteControlClient API with Android 5.0. Instead, Google has introduced a new API, MediaSession as its replacement. With the Notification.MediaStyle template introduced in Lollipop, it allows you to add media control as playback notification on the lock screen with greater control as to which buttons are displayed.

Documentation

Media Control Behavior Changes: http://developer.android.com/about/versions/android-5.0-changes.html#BehaviorMediaControl

MediaStyle Class Reference: http://developer.android.com/reference/android/app/Notification.MediaStyle.html RemoteControlClient(deprecated)

Class Reference: http://developer.android.com/reference/android/media/RemoteControlClient.html

Note that with Android 5.0, the system no longer shows RemoteControlClient objects on the lock screen.

Resolution

Currently Google has not announced backwards compatibility for new MediaSession API. In order to add media control on the lockscreen for Android 4.0 and Android 5.0, you will need to add support for both RemoteControlClient API and MediaSessionAPI until minSdkVersion rises to 21 or higher. You can make the app distinguish which API to use by the following code:

if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH)  
     && ((Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP))) {
     // your code using RemoteControlClient API here - is between 14-20
} else if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
     // your code using MediaSession API here - is api 21 or higher
}

Keywords: Media Control, MediaSession, Lockscreen, deprecated methods

[KB_0032]

androidlollipop
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Article

Contributors

rossbria contributed to this article brizzlebrazzle contributed to this article