I have been trying to build an audio podcast app in which I need one feature of playing audio that should show in the notification bar/ lock screen just like any other music app.
For that, I have used SimpleExoPlayer
for media, and PlayerControlView
for UI.
For feature, I have used MediaBrowserServiceCompat
by following official docs. I have taken the reference of UAMP app demo provided by Android Devs too.
But in all these, they are handling media through MediaPlayer
rather than ExoPlayer
and PlayerControlView
MainActivity
have UI/view and instance of SimpleExoPlayer
. Which I am creating inside the activity as follows.
// Creating common instance of PlayerView
val renderersFactory = DefaultRenderersFactory(this@MainActivity)
val trackSelectionFactory = AdaptiveTrackSelection.Factory()
val trackSelectSelector = DefaultTrackSelector(trackSelectionFactory)
val loadControl = DefaultLoadControl()
exoPlayer = ExoPlayerFactory.newSimpleInstance(this@MainActivity, renderersFactory, trackSelectSelector, loadControl)
// Attachig player of playerview to the exoplayer
binding.bottomSheetParent.playerView.player = exoPlayer
The problem is that MediaBrowserServiceCompat
will have the player and the activity will have the view. No one of them will have both to be able to attach players to view.
So, how can I pass the player from Service (that is not Serializable or Parcelable) to Activity or how can I pass a player view to the Service?