title: MediaBrowserService with ExoPlayer and PlayerControlView - How to access to the player instance from the UI (PlayerControlView)?
body: <p>I am currently working on a part of an app which has video and audio functionality, and started refactor the code base recently. The goal is to integrate <code>MediaSession/ MediaController</code> and <code>MediaBrowserService/ MediaBrowser</code> framework.</p>
  
  <p>We use <code>ExoPlayer</code> and <code>PlayerControlView</code> more specific, the <a href="https://exoplayer.dev/doc/reference/com/google/android/exoplayer2/ui/PlayerView.html" rel="noreferrer">PlayerView</a> for both video and audio components, and it requires the reference to the player instance for the <code>PlayerControlView</code>:</p>
  
  <pre><code>/**
     * Sets the {@link Player} to control.
     *
     * @param player The {@link Player} to control, or {@code null} to detach the current player. Only
     *     players which are accessed on the main thread are supported ({@code
     *     player.getApplicationLooper() == Looper.getMainLooper()}).
     */
    public void setPlayer(@Nullable Player player) {...
  </code></pre>
  
  <p>However, under the <a href="https://developer.android.com/guide/topics/media-apps/audio-app/building-a-mediabrowser-client" rel="noreferrer">android developers post</a> and the <a href="https://developer.android.com/reference/android/service/media/MediaBrowserService" rel="noreferrer">documentation</a> of <code>MediaBrowserService</code>, the player instance should be contained under the service. In addition, the only way for the client site (MediaBrowser and MediaController) to talk to service it through the <code>connect()</code> method and <a href="https://developer.android.com/reference/android/media/browse/MediaBrowser.ConnectionCallback" rel="noreferrer">MediaBrowserConnectionCallback</a>, which makes passing the instance of the player to the PlayerControlView (or the other way around) not possible.</p>
  
  <p>I have tried using the various callbacks such as the <a href="https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat.Callback" rel="noreferrer">MediaSessionCompat.Callback</a>, but neither of the <a href="https://exoplayer.dev/doc/reference/com/google/android/exoplayer2/SimpleExoPlayer.html" rel="noreferrer">SimpleExoPlayer</a> or the <a href="https://exoplayer.dev/doc/reference/com/google/android/exoplayer2/ui/PlayerControlView.html" rel="noreferrer">PlayerControlView</a> are Parcelable. </p>
  
  <p>In the traditional service, we uses <code>Binder</code> to access the methods we declared within the service and do something like:</p>
  
  <pre><code>boolean attachPlayerControlView(PlayerControlView playerControlView) {
              if (player != null) {
                  playerControlView.setPlayer(player);
                  return true;
              }
              return false;
          }
  </code></pre>
  
  <p>However, this seems no possible with the <code>MediaBrowserService/ MediaBrowser</code> framework. I checked the answer to this <a href="https://stackoverflow.com/q/50100364/4574311">question</a>, which indicates that using [sendCommand] is a way to call custom methods. But it also requires the parameters to be Parcelable.</p>
  
  <p>To sum up, my question is, is there a way to have the <code>PlayerControlView</code> access to the instance of <code>SimpleExoPlayer</code> or the other way around under the <code>MediaBrowserService</code> framework.</p>
  
  <p>Many thanks ahead for any answer or comments.</p>