title: Android MediaRouter Volume events
body: <p>I want to implement volume change as seen in Youtube app while casting, like if app is in background or on lock screen </p>
  
  <p><a href="http://i.stack.imgur.com/sJBOd.png" rel="noreferrer">Like this</a></p>
  
  <pre><code>private void createSession() {
      ComponentName receiver = new ComponentName(getPackageName(), RemoteReceiver.class.getName());
      mediaSession = new MediaSessionCompat(this, "PlayerService", receiver, null);
      mediaSession.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS |
              MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
      mediaSession.setPlaybackState(new PlaybackStateCompat.Builder()
              .setState(PlaybackStateCompat.STATE_PLAYING, 0, 1f)
              .setActions(PlaybackStateCompat.ACTION_PLAY_PAUSE)
              .build());
      AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
      audioManager.requestAudioFocus(new AudioManager.OnAudioFocusChangeListener() {
          @Override
          public void onAudioFocusChange(int focusChange) {
              // Ignore
          }
      }, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
      mediaSession.setActive(true);
  
      mediaRouter = MediaRouter.getInstance(this);
      mediaRouter.setMediaSessionCompat(mediaSession);
  }
  </code></pre>
  
  <p>Now I get the slider just like Image above and it responds to volume buttons, but I dont receive change in my broadcast receiver.</p>