List of usage examples for android.support.v4.media.session MediaSessionCompat setCallback
public void setCallback(Callback callback)
From source file:MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); MediaSessionCompat mediaSession = new MediaSessionCompat(this, getApplication().getPackageName()); mediaSession.setCallback(mMediaSessionCallback); mediaSession.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS); mediaSession.setActive(true);/* w ww . j a va2 s . c om*/ PlaybackStateCompat state = new PlaybackStateCompat.Builder().setActions(PlaybackStateCompat.ACTION_PLAY | PlaybackStateCompat.ACTION_PLAY_PAUSE | PlaybackStateCompat.ACTION_PAUSE | PlaybackStateCompat.ACTION_SKIP_TO_NEXT | PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS).build(); mediaSession.setPlaybackState(state); }
From source file:com.doctoror.fuckoffmusicplayer.data.media.session.MediaSessionFactoryImpl.java
@NonNull @Override/*from w ww. ja v a2s. co m*/ public MediaSessionCompat newMediaSession() { final MediaSessionCompat mediaSession = new MediaSessionCompat(context, TAG_MEDIA_SESSION, mediaButtonReceiver, mediaButtonIntent); mediaSession.setCallback(mediaSessionCallback); mediaSession.setFlags( MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS); mediaSession.setSessionActivity(PendingIntent.getActivity(context, 1, new Intent(context, sessionActivityClass), PendingIntent.FLAG_UPDATE_CURRENT)); mediaSession.setActive(true); return mediaSession; }
From source file:org.chromium.chrome.browser.media.ui.MediaNotificationManager.java
private MediaSessionCompat createMediaSession() { MediaSessionCompat mediaSession = new MediaSessionCompat(mContext, mContext.getString(R.string.app_name), new ComponentName(mContext.getPackageName(), getButtonReceiverClassName()), null); mediaSession.setFlags(/*w ww . j av a 2 s . c o m*/ MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS); mediaSession.setCallback(mMediaSessionCallback); // TODO(mlamouri): the following code is to work around a bug that hopefully // MediaSessionCompat will handle directly. see b/24051980. try { mediaSession.setActive(true); } catch (NullPointerException e) { // Some versions of KitKat do not support AudioManager.registerMediaButtonIntent // with a PendingIntent. They will throw a NullPointerException, in which case // they should be able to activate a MediaSessionCompat with only transport // controls. mediaSession.setActive(false); mediaSession.setFlags(MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS); mediaSession.setActive(true); } return mediaSession; }