Java Code Examples for android.support.v4.media.session.MediaSessionCompat#getSessionToken()

The following examples show how to use android.support.v4.media.session.MediaSessionCompat#getSessionToken() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MusicService.java    From klingar with Apache License 2.0 5 votes vote down vote up
@Override public void onCreate() {
  super.onCreate();
  Timber.d("onCreate");
  KlingarApp.get(this).component().inject(this);

  Playback playback = new LocalPlayback(getApplicationContext(), musicController, audioManager,
      wifiManager, client);
  playbackManager = new PlaybackManager(queueManager, this, AndroidClock.DEFAULT, playback);

  session = new MediaSessionCompat(this, "MusicService");

  try {
    MediaControllerCompat mediaController =
        new MediaControllerCompat(this.getApplicationContext(), session.getSessionToken());
    musicController.setMediaController(mediaController);
  } catch (RemoteException e) {
    Timber.e(e, "Could not create MediaController");
    throw new IllegalStateException();
  }

  session.setCallback(playbackManager.getMediaSessionCallback());

  Context context = getApplicationContext();
  Intent intent = new Intent(context, KlingarActivity.class);
  session.setSessionActivity(PendingIntent.getActivity(context, 99, intent, FLAG_UPDATE_CURRENT));

  playbackManager.updatePlaybackState();

  mediaNotificationManager = new MediaNotificationManager(this, musicController,
      queueManager, rx);

  castSessionManager = CastContext.getSharedInstance(this).getSessionManager();
  castSessionManagerListener = new CastSessionManagerListener();
  castSessionManager.addSessionManagerListener(castSessionManagerListener, CastSession.class);

  mediaRouter = MediaRouter.getInstance(getApplicationContext());

  timelineManager = new TimelineManager(musicController, queueManager, media, rx);
  timelineManager.start();
}