Example usage for android.media.session MediaSession setMediaButtonReceiver

List of usage examples for android.media.session MediaSession setMediaButtonReceiver

Introduction

In this page you can find the example usage for android.media.session MediaSession setMediaButtonReceiver.

Prototype

public void setMediaButtonReceiver(@Nullable PendingIntent mbr) 

Source Link

Document

Set a pending intent for your media button receiver to allow restarting playback after the session has been stopped.

Usage

From source file:org.opensilk.video.playback.PlaybackService.java

private MediaSession newMediaSession() {
    final MediaSession mediaSession = new MediaSession(mContext, "SilkVideoPlayer");
    mediaSession//  www.  j a v a2 s. co  m
            .setFlags(MediaSession.FLAG_HANDLES_MEDIA_BUTTONS | MediaSession.FLAG_HANDLES_TRANSPORT_CONTROLS);
    final ComponentName mediaButtonComponent = new ComponentName(mContext, MediaButtonReceiver.class);
    final PendingIntent mediaButtonIntent = PendingIntent.getBroadcast(mContext, 1,
            new Intent().setComponent(mediaButtonComponent), PendingIntent.FLAG_UPDATE_CURRENT);
    mediaSession.setMediaButtonReceiver(mediaButtonIntent);
    mediaSession.setSessionActivity(makeActivityIntent(null));
    return mediaSession;
}