Thanks to this forum, I’m having success with controlling time with my imported videos. I’d like to stop the animation at, say 5:11 seconds. How would I write that in js?
Run this ‘on scene load’ in the scene where your video is placed: You need to make a listener for the timeupdate value your video’s Element ID, then create an ‘if’ statement for when that time has passed (60 * 5) + 11, which is 311 seconds. Then you need to stop the animation on a timeline:
document.getElementById('myvideo').addEventListener('timeupdate', function() {
var videoCurrentTime = document.getElementById('myvideo').currentTime;
if (videoCurrentTime >= 311) {
hypeDocument.pauseTimelineNamed('Main Timeline')
}
If you meant 5 seconds and 11 frames, it would be: 5.36 instead of 311. (This is 11 divided by 30).
Got it. Thanks. I can use both of those. I have the listener ‘on scene load’, but I didn’t know how to get the time to be more precise. More js to learn…
I new with Hype and I still got problem making videos pause at “On Scene Load” with your code, I tried using the video name with and without the .mp4 file extension and nothing happens. I tried everything like adding a timeline actions with this code, changing ’ with " and nothing. I attached some screenshot hope it helps. Oh and almost forgot something that could be important, I’m using the Hype Pro trial maybe this could be the problem.
document.getElementById('video1').addEventListener('timeupdate', function() {
var videoCurrentTime = document.getElementById('video1').currentTime;
console.log(videoCurrentTime);
if (videoCurrentTime >= 3) {
// this will pause the main timeline when the Video has played 3 or more seconds:
hypeDocument.pauseTimelineNamed('Main Timeline');
// this will pause the video also. You can resume with .play();
document.getElementById('video1').pause();
}
})