I'm building a podcast player using the Exoplayer. I've managed to set it up to have the controls both in the layout and the notification bar using exoplayer's PlayerNotificationManager. The problem is, with it tied to the fragment, it stops playing whenever onPause(), onStop() are called, as to be expected.
So I went about making a ForegroundService to run the exoplayer so it would remain playing, which was quite successful, however, the controls in the layout no longer function and only the notification bar controls work.
The service itself is doing what it should, but I'm not sure what I need to do to make the layout controls respond as well.
I'm basically trying to build a standard media player, but I've kinda at a loss for this. The primary focus for exoplayer seems to be video, and I understand its a little heavy compared to mediaplayer. I mainly focused on it because the controls handle beautifully
Does anyone have any advice for how to make exoplayer play nicely in a service with notification bar controls and layout controls?
class PodcastPlayFragment: Fragment(){
private val connection = object : ServiceConnection{
override fun onServiceConnected(name: ComponentName?, service: IBinder?) {
if (service is PlayPodcastService.PlayPodcastServiceBinder) {
playerControlView.player = service.getExoPlayer()
}
}
}
class PlayPodcastService: Service{
inner class PlayPodcastServiceBinder: Binder(){
fun getExoPlayer() = simpleExoPlayer
}
}
After a little playing around I realized in
onBind()I wasn't returning anIBinderobject. Creating an IBinder and returning it ononBind()solved the problem.