Introduction
The Android SDK v9.0 decouples the foreground service from its core, introducing breaking changes compared to previous versions. The foreground service is used mainly for background playback and downloading media to store on the device. The code will need adjustment if the application uses one or both of these features.
Before the Android SDK v9.0, the previous versions used to create the notification for background playback and background download automatically. Due to policy changes in the Google Play Store for applications targeting Android 14 and above, starting from v9.0, only applications that offer one or both features should explicitly implement the plugins Offline-Playback and Playback-Notification.
Background Playback updates
With Android SDK v9.0, the new plugin Playback-Notification was introduced, which helps create notifications for background playback. If your application does not offer background playback but you are planning to implement it, see Background Playback for more details.
If your application already offers background playback, follow the next instructions to migrate to the new plugin:
Breaking updates
The following classes were affected by the updates:
- The
BrightcoveNotification
class has been replaced with thePlaybackNotification
class. - The
MediaPlaybackService
class has been moved into the newPlayback-Notification
plugin. - The
PlaybackNotification
changed from being a Class to being an Interface. - The
PlaybackNotification.Config
class has been renamed toBackgroundPlaybackNotification
.
Creating the notification
Here is the list of steps for creating the notification:
-
Include the new plugin in your
build.gradle
file:dependencies { implementation "com.brightcove.player:android-playback-notification-plugin:[SDK_VERSION]" }
-
In the activity where Brightcove Player lives, you can create the
PlaybackNotification
through theBackgroundPlaybackNotification
class.- Here is the Kotlin version:
// Kotlin val videoDisplayComponent = baseVideoView.videoDisplay as ExoPlayerVideoDisplayComponent? val myNotification = BackgroundPlaybackNotification.getInstance(this)
- Here is the Java version:
// Java ExoPlayerVideoDisplayComponent displayComponent = ((ExoPlayerVideoDisplayComponent) brightcoveVideoView.getVideoDisplay()); PlaybackNotification myNotification = BackgroundPlaybackNotification.getInstance(this);
- Here is the Kotlin version:
-
The
BackgroundPlaybackNotification
class will create a default notificationThe notification requires a
config
object; the default action is to set a newPlaybackNotificationConfig
object. Finally, the notification will require the player that will be attached to it:- Here is the Kotlin version:
// Kotlin myNotification?.setConfig(PlaybackNotificationConfig(this)) myNotification?.playback = videoDisplayComponent?.playback
- Here is Java version:
// Java myNotification.setConfig(new PlaybackNotificationConfig(this)); myNotification.setPlayback(displayComponent.getPlayback());
- Here is the Kotlin version:
-
Once the notification is created and configured, it is set in the
ExoPlayerVideoDisplayComponent
class:- Here is the Kotlin version:
// Kotlin videoDisplayComponent?.let { videoDisplayComponent.playbackNotification = myNotification }
- Here is the Java version:
// Java if (videoDisplayComponent != null ) { videoDisplayComponent.setPlaybackNotification(createPlaybackNotification()); }
- Here is the Kotlin version:
-
Here is the complete code:
- Here is the Kotlin version
// Kotlin val videoDisplayComponent = baseVideoView.videoDisplay as ExoPlayerVideoDisplayComponent? val myNotification = BackgroundPlaybackNotification.getInstance(this) myNotification?.setConfig(PlaybackNotificationConfig(this)) myNotification?.playback = videoDisplayComponent?.playback videoDisplayComponent?.let { videoDisplayComponent.playbackNotification = myNotification }
- Here is the Java version:
// Java ExoPlayerVideoDisplayComponent displayComponent = ((ExoPlayerVideoDisplayComponent) brightcoveVideoView.getVideoDisplay()); PlaybackNotification notification = BackgroundPlaybackNotification.getInstance(this); myNotification.setConfig(new PlaybackNotificationConfig(this)); myNotification.setPlayback(displayComponent.getPlayback()); if (videoDisplayComponent != null ) { videoDisplayComponent.setPlaybackNotification(createPlaybackNotification()); }
- Here is the Kotlin version
Offline Playback updates
Downloading media to play it offline later requires integrating the Offline-Playback plugin in your build.gradle
file manually:
dependencies {
implementation "com.brightcove.player:offline-playback:[SDK_VERSION]"
}
Finally, in the activity where Brightcove Player lives, it is necessary to set a MediaStore
through the ExoPlayerVideoDisplayComponent
class:
- Here is the Kotlin version:
// Kotlin val videoDisplayComponent = baseVideoView.videoDisplay as ExoPlayerVideoDisplayComponent? videoDisplayComponent?.let { videoDisplayComponent.setMediaStore = OfflineStoreManager.getInstance(this) }
- Here is the Java version:
// Java ExoPlayerVideoDisplayComponent videoDisplayComponent = ((ExoPlayerVideoDisplayComponent) brightcoveVideoView.getVideoDisplay()); if (videoDisplayComponent != null) { videoDisplayComponent.setMediaStore(OfflineStoreManager.getInstance(this)); }