Android SDK v9.0 Migration Guide

In this topic, you will learn about the new improvements and features in the major version release of Android SDK v9.0.

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 the PlaybackNotification class.
  • The MediaPlaybackService class has been moved into the new Playback-Notification plugin.
  • The PlaybackNotification changed from being a Class to being an Interface.
  • The PlaybackNotification.Config class has been renamed to BackgroundPlaybackNotification.

Creating the notification

Here is the list of steps for creating the notification:

  1. Include the new plugin in your build.gradle file:

                        dependencies {
                            implementation "com.brightcove.player:android-playback-notification-plugin:[SDK_VERSION]"
                            }
                        
                
  2. In the activity where Brightcove Player lives, you can create the PlaybackNotification through the BackgroundPlaybackNotification 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);
                                  
                              
  3. The BackgroundPlaybackNotification class will create a default notification

    The notification requires a config object; the default action is to set a new PlaybackNotificationConfig 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());
                                  
                              
  4. 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());
                                      }
                                  
                              
  5. 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());
                                      }
                                  
                              

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));
                            }