@Override
 public void onDisconnected() {
   LogHelper.d(TAG, "onDisconnected");
   mSessionExtras.remove(EXTRA_CONNECTED_CAST);
   mSession.setExtras(mSessionExtras);
   Playback playback = new LocalPlayback(MusicService.this, mMusicProvider);
   mMediaRouter.setMediaSession(null);
   switchToPlayer(playback, false);
 }
 @Override
 public void onApplicationConnected(
     ApplicationMetadata appMetadata, String sessionId, boolean wasLaunched) {
   // In case we are casting, send the device name as an extra on MediaSession metadata.
   mSessionExtras.putString(EXTRA_CONNECTED_CAST, mCastManager.getDeviceName());
   mSession.setExtras(mSessionExtras);
   // Now we can switch to CastPlayback
   Playback playback = new CastPlayback(MusicService.this, mMusicProvider);
   mMediaRouter.setMediaSession(mSession);
   switchToPlayer(playback, true);
 }