Copy link to clipboard
Copied
Hello everybody,
i have a problem: i have a video component
i imported in a html5 canvas. I managed to control the video trough buttons, but i need to pause a video without the buttons.
I mean, i need the video to play and pause after 3 sec. The instance i gave to the video is "myVideo"
i tried the snipped code of animate, but nothing work. When i play the video trough button, there is no way to stop it at second 2.
Is there out there anyone willing to help me? thank u.
Copy link to clipboard
Copied
this is the action i gave to the document:
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
The above code pauses the video 3 seconds after the page initializes, not 3 seconds into the video. If the user takes more than 3 seconds to click the play button, the video won't even play at all.
To pause a video at a certain number of seconds, you have to monitor the actual time index of the video. This seems to work:
var _pauseTime = 3.0;
this.myPlayButton.addEventListener("click", fl_MouseClickHandler);
function fl_MouseClickHandler(e) {
var vid = $("#myVideo")[0];
vid.play();
vid.addEventListener("timeupdate", vidTime);
}
function vidTime(e) {
var vid = e.target;
if (vid.currentTime >= _pauseTime) {
vid.removeEventListener("timeupdate", vidTime);
vid.pause();
}
}
Copy link to clipboard
Copied
Be aware that on mobile devices videos will not autoplay, so if there are no controls available, mobile users will be stuck.
Copy link to clipboard
Copied
thank u!
Copy link to clipboard
Copied
@ClayUUID you could also check if it's been 3 seconds since the play button was clicked, but you're correct; the code i previously posted doesn't do that. this does (i believe):
Copy link to clipboard
Copied
I'd still not recommend this approach, since if anything interrupts playback, e.g. buffering, the video won't pause at the correct point.
Copy link to clipboard
Copied
good point.