This is a great use case in addition to Marc Bächinger’s Playback Notifications with ExoPlayer. Coinverse uses the PlayerNotificationManager outlined in Marc’s post in order to display a notification player for audiocasts. Then, the pattern above is implemented to return a SimpleExoPlayer instance that displays the player in the main view when the app is opened.

For Android 9.0 it’s important to refactor startService(...) with ContextCompat.startForegroundService(...). Otherwise, if a service is attempted to be stopped when no Foreground Services are running, there will be a Null Pointer Exception crash.



Open Sourcer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store