Skip to main content

Background Playback

What you learn​

You're instantiating DIVA Player in your app (mobile/TV) and relying on DIVA Back Office as the video streaming source.

The goal of this article is to build the simplest front-end to stream a video from the DIVA Back Office, having the possibility to control and modify Background Playback configuration parameter dynamically and remotely.

Before starting​

  • Ensure the DIVA Back Office instance you rely on is up and running.
  • Ask your video engineers team <videoId>, <settingsURL>, <languageCountryCode>, <userToken> and <sharedKey>.
  • Ensure the settings file contains the backgroundDurationThreshold parameter.

Instantiation iOS logo​

The Basic instantiation code is sufficient.

In the settings file, the backgroundDurationThreshold must contain the configuration, like in the following example:

      "settings": {
"backgroundDurationThreshold": 60000 //milliseconds, optional(null)
}

Here's an enhanced description of the parameter:

backgroundDurationThreshold​

It improves the performance and reliability of the DIVA player when transitioning between background and foreground states. By setting a threshold for the duration of background activity, the app can manage player instances more effectively, ensuring optimal playback quality and system resource utilization.

  • Performance Impact: By restarting the player instance only if it has been in the background longer than backgroundDurationThreshold, the app efficiently manages memory and system resources. After a prolonged background period, restarting the player ensures that any cached or stale data is cleared, and resources are refreshed. This process minimizes memory usage, prevents potential data inconsistencies, and reduces the risk of encountering playback errors upon returning to foreground.
  • SPI Reliability: Restarting the player after extended background time helps reset SPI metrics to a fresh state. This results in more accurate tracking of playback quality, session duration, and start-up metrics, as any residual or outdated data from the previous session is cleared.

How it works​

  • When entering background mode, the app records the timestamp.

  • When returning to foreground:

    • If the time difference is greater than backgroundDurationThreshold, the Diva player instance is restarted, creating a fresh playback session and optimizing system resources.
    • If the time difference is less than backgroundDurationThreshold, playback resumes from its current state without restarting.
  • Exceptions: If the player was in AirPlay, Chromecast, or Picture-in-Picture (PiP) mode before backgrounding, playback will resume directly without a restart.

  • Diva Player Instance Management: Player instances are automatically destroyed and recreated upon exceeding the backgroundDurationThreshold, improving playback reliability and reducing unnecessary memory use.

  • SSAI Session Handling: SSAI (Server-Side Ad Insertion) sessions terminate when the threshold is exceeded, with new sessions initialized upon reactivation to ensure accurate ad tracking.

  • VOD Decoder Optimization: The VOD decoder is released after prolonged background activity, freeing resources for efficient playback upon return.