Forum Discussion
Pausing the timeline when the player window is not active (in focus)
I'm pretty sure the Storyline is already pausing the timeline when the course window is not in focus, and resuming when it's focused again. For instance, if the user has switched to another tab or minimized the browser. It should work similar to the "visibilitychanged' event fired at the document when the contents of its tab have become visible or have been hidden (MDN). I'm not a JavaScript expert, so I hope someone else will step in with more information. Basic example in the Storyline would be:
let courseActive = true;
let player = GetPlayer().GetVar()
player.SetVar('courseActive', courseActive)
function handleVisibilityChange() {
if (document.hidden) {
// User switched to another tab or minimized the browser
courseActive = false;
player.SetVar('courseActive', courseActive)
} else {
// User returned
courseActive = true;
player.SetVar('courseActive', courseActive)
}
}
// Event listener to detect visibility changes
document.addEventListener("visibilitychange", handleVisibilityChange);
Related Content
- 10 months ago