Forum Discussion

JennySaucerman-'s avatar
JennySaucerman-
Community Member
31 days ago

xAPI for user pausing and playing video

I'm trying to capture if and when a user clicks the pause/play button in the Storyline player while watching a video using xAPI. It seems like it should be simple, but I'm struggling to find a way to...
  • Nedim's avatar
    Nedim
    4 days ago

    I run this JavaScript code when the timeline starts: 

    let video = document.getElementsByTagName('video')[0];
    video.ontimeupdate = () => setVar('isVideoPlaying', !video.paused && !video.ended);

    The script listens for the "ontimeupdate" event, which is triggered regularly as the video plays. Each time the event fires, it checks whether the video is currently playing, paused, or ended, and updates the variable "isVideoPlaying" accordingly.

    I could have targeted the video play/pause button as well, but that wouldn't work if the video controls are hidden. This script however, will work regardless of whether the controls are visible or not. I have attached the .story file used in this example for your reference.