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.
If the user is not watching a video, or the video is paused, moving to background mode will stop updating the screen. 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.
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.
Auto Background
If you would like your app to enter background mode whenever the user is not actively interacting with it, you can enable Auto Background mode. This will switch to the background automatically after a period of inactivity.
This works whether or not video is playing. You can set the timeouts for both cases separately. In this example, the timeout is set to 30 seconds if video is playing, and 15 seconds if video is not playing.
senza.lifecycle.configure({
autoBackground: {
enabled: true,
timeout: {playing: 30, idle: 15}
}
});
In the simplest case, you can turn the feature on when your app starts up so that it is enabled all of the time. Alternatively, you can enable or disable auto-background or modify the timeouts while your app is running, depending upon the use case of your app.
Updated 2 days ago