Instant Resume enables Roku Scenegraph channel to save its current state upon exit and then continue playback upon next launch. This improves the user experience by letting users quickly get back to the content they were watching before. This example code demonstrates how to implement Instant Resume in a roku channel. It takes the completed SceneGraph master sample channel, and does the following:
-
Updates the channel manifest with required attributes.
-
Implements the required suspend and resume handlers.
-
Adds signal beacons to measure channel suspend and resume times.
Channel manifest declare the sdk_instant_resume=1
and run_as_process=1
attributes.
-
sdk_instant_resume=1. Acknowledges that the channel has implemented all the requirements and protocols for the Instant Resume integration.
-
run_as_process=1. Enables the Roku OS to preserve the channel state in the device RAM when the channel is suspended.
The videoPlayerLogic.brs file includes onMainSceneSuspend
and onMainSceneResume
callback functions for when the channel is suspended and resumed from a channel exit, respectively. These callback functions are defined in the MainScene.XML
component.
-
onMainSceneSuspend. When the channel is suspended after being exited, this callback function checks whether the channel was exited because the Home button was pressed on the Roku remote control. If the Home button was pressed and the viewer was watching content, they are returned to the Details sceen upon the relaunching the channel. The user can the resume playback or start watching from the beginning.
-
onMainSceneResume. When the channel is resumed, this callback function checks whether it recevied any launch parameters. If so, the channel deeplinks into the content specified by the
contentId
using the launch behavior required by the specifiedmediaType
.
The onMainSceneResume
callback function in the videoPlayerLogic.brs file fires the AppResumeComplete beacon. This beacon must be fired when the suspended scene is fully rendered during the resume process and when video playback starts after handling a deep link, once the channel can respond to commands sent via the Roku remote control.