Forum Discussion
Video timestamp
I have searched for this and had a couple of failed attempts using javascript. Can I get the current timestamp of a video on the slide.
For context the video plays independent of the timeline and has a scrubber and I want to trigger specific items at specific times of the video. I will continue messing with javascript and post the results if I find an answer
Hi Phil,
I've been working on a similar concept for a while now. I've successfully manipulated the video independently from the timeline. This is the basic set up to integrate with Storyline:
let video = document.getElementsByTagName('video')[0];
video.duration;
video.currentTime;
video.ontimeupdate = function() { getVideoTimes() };
function getVideoTimes() {
let player = GetPlayer();
player.SetVar('currentTime', video.currentTime);
player.SetVar('duration', video.duration);
console.log(video.currentTime);
console.log(video.duration);
}
5 Replies
- NedimCommunity Member
Hi Phil,
I've been working on a similar concept for a while now. I've successfully manipulated the video independently from the timeline. This is the basic set up to integrate with Storyline:
let video = document.getElementsByTagName('video')[0];
video.duration;
video.currentTime;
video.ontimeupdate = function() { getVideoTimes() };
function getVideoTimes() {
let player = GetPlayer();
player.SetVar('currentTime', video.currentTime);
player.SetVar('duration', video.duration);
console.log(video.currentTime);
console.log(video.duration);
}- PhilMayorSuper Hero
Hi Nedim
Thanks for posting. That was almost the same as I have. I used the help you gave me on a previous post on videos and used that to get the duration.
Thanks again.
Phil
Sent from my iPhone
- NedimCommunity Member
Great, no problem. Anytime.
- Jean-MichelRaibCommunity Member
Hi Nedim,
I am also trying to get the current playhead time location of a video back in a variable, when opening a layer (trigger : chronology of this layer starts then javascript)
This code did not work for me.
video.currentTime shows "undefined" in the console.
Any idea ?
Thank you.
- NedimCommunity Member
It works on my end. Excluding any syntax errors, it appears that the video may not be fully loaded or not available at the time the script is executed. I’m not sure how your current setup is structured. To speed up troubleshooting, you could upload a simple slide that matches your scenario. Alternatively, you can run the script using an interval and stop it once the video element is found and fully loaded. Also, if the video hasn’t started playing, ontimeupdate will never fire.
Related Content
- 1 year ago
- 10 months ago
- 10 months ago