Switching Modes

The client library inlcudes a Lifecycle object that can be used to switch between foreground and background modes. You can use the functions lifecycle.moveToBackground() and lifecycle.moveToForeground().

When the user starts watching a video full screen, you can move to background mode, perhaps after a delay of a few seconds in case they want to continue interacting with your app. Then the video will continue playing in the Remote Player.

If the user is not watching a video in the Remote Player, or the video is paused, moving to background mode will stop updating the screen. When that happens, it will continue showing the last frame rendered by the browser. The JavaScript engine will continue running your app, but any updates it makes will not be shown until you switch back to foreground mode.

Auto Background

Senza will switch to background mode automatically after a period of inactivity. This helps to make sure that your app doesn't stay in foreground mode for too long when the user is not interacting with it.

The Auto Background feature works just like moving to background manually, except on a timer. If video is playing in the Remote Player it will stream the video from the CDN; otherwise it will stop updating the screen. There are separate timeouts for each of these two cases.

You can control whether the feature is enabled and set the timeouts like this:

senza.lifecycle.configure({
  autoBackground: {
    enabled: true,
    timeout: {playing: 30, idle: 15}
  }
});

By default, the feature is enabled with both timeouts set to ten minutes. See the lifecycle.configure() reference for more details.

In some cases you may wish to disable the Auto Background feature, for example if your app plays video exclusively in the browser, or you have a digital signage application that updates the page without any user interaction.

Returning to foreground

When your app is in background mode and the user presses a button on the remote control, you'll want to switch back to foreground mode so that your app can respond to their input.

For non-interactive apps, you can move back to foreground after a pre-determined amount of time using a timer or the Alarm Manager.

If you are using the client library's Shaka Player subclass for playing video, it will also move back to foreground automatically when the video ends. If you are playing video directly in the Remote Player, you can listen for an ended event and move back to the foreground manually.