Background playback

With   v2.0 of the Android SDK, we're introducing the background playback feature, which ensures the video playback experience isn't interrupted even when your Android application is not in the foreground. This addition means the player can keep playing video content when the user works with another app or when the device is locked.

Override the default behavior

When the application hosting the Wowza Flowplayer goes into the background, the playback is paused by default. This behavior prevents users from unintentionally consuming data or draining their battery.

In some scenarios, you may want to continue background playback instead of pausing it. Therefore, you have the ability to override the default behavior using the setShouldPauseOnBackground() method. This method accepts the shouldPauseOnBackground parameter and the values explained in the following table.

Parameter Value Description
shouldPauseOnBackground true The video playback pauses when the host activity's OnPause() method is called. This is useful if you want the video to stop when the user is not actively interacting with your application.
shouldPauseOnBackground false The video playback continues even when the host activity is in the paused state. The audio from the video continues to play even if the application is in the background.

To continue video playback even when the application is in the background, you can call the setShouldPauseOnBackground() method on your flowplayer instance:

Copy
Copied
flowplayer.setShouldPauseOnBackground(false)
info

It's important to call the setShouldPauseOnBackground() method before the user navigates out of the app, so we suggest invoking it right after your player instance is initialized. For more see, Create a player instance.

Manage media session notifications

With the background playback capability, a sticky media session notification is added informing users about the ongoing playback. Tapping this notification can invoke a custom action that's determined by your application's requirements.

Wowza Flowplayer Android SDK background playback notification

Set an intent for media notifications

You can set a custom intent to be triggered when the media session notification is tapped. To accomplish this task, use the PendingIntent Android class and the setMediaNotificationTapIntent() method provided by the Android SDK:

Copy
Copied
flowplayer.setMediaNotificationTapIntent(pendingIntent: PendingIntent)

The pendingIntent parameter you pass determines the custom activity to launch when the user taps the media notification.

tip

Always remember to provide an intuitive experience for your users. If you allow background playback, it's a good practice to also give them quick access back to your application through the media notification.

Example

Let's take an example where you want to bring users back to the playback screen of your application when they tap on the media notification.

You can prepare a PendingIntent object that defines what should happen when the user taps the media notification, then associate that intent with the activity hosting your media playback. Inside your playback activity, your code snippet should look similar to this:

Copy
Copied
// Create an immutable PendingIntent object that launches the activity hosting the player
val pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_IMMUTABLE)
flowplayer.setMediaNotificationTapIntent(pendingIntent)