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 MediaSession/ MediaController
and MediaBrowserService/ MediaBrowser
framework.
We use ExoPlayer
and PlayerControlView
more specific, the PlayerView for both video and audio components, and it requires the reference to the player instance for the PlayerControlView
:
/**
* 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) {...
However, under the android developers post and the documentation of MediaBrowserService
, 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 connect()
method and MediaBrowserConnectionCallback, which makes passing the instance of the player to the PlayerControlView (or the other way around) not possible.
I have tried using the various callbacks such as the MediaSessionCompat.Callback, but neither of the SimpleExoPlayer or the PlayerControlView are Parcelable.
In the traditional service, we uses Binder
to access the methods we declared within the service and do something like:
boolean attachPlayerControlView(PlayerControlView playerControlView) {
if (player != null) {
playerControlView.setPlayer(player);
return true;
}
return false;
}
However, this seems no possible with the MediaBrowserService/ MediaBrowser
framework. I checked the answer to this question, which indicates that using [sendCommand] is a way to call custom methods. But it also requires the parameters to be Parcelable.
To sum up, my question is, is there a way to have the PlayerControlView
access to the instance of SimpleExoPlayer
or the other way around under the MediaBrowserService
framework.
Many thanks ahead for any answer or comments.
MediaBrowserService
, to be more specific, we gave up the benefit of using thePlayerControlView
with theExoPlayer
. Which means we had to do a lot of heavy lifting work on our own. For Video, we removed the usage ofMediaBrowserService
andMediaBrowser
, since it seems unnecessary and the use ofMediaSession
/MediaController
is enough. – Gnosticism