Reputation: 506
I am designing an app which uses HTML 5 video. When I seek while the video is running "video pause" event is fired which in turns affect my logic for actions which has to happen during seeking. Is there a way by which I can remove this pause event or find that particular pause events which happen with seeking?
Upvotes: 8
Views: 3008
Reputation: 29
In this case, you should know why the video pauses when you seek this with bar control. Actually when you seek, the video will be loading the timeline and will pause until it's done.
You can listen for the event onPause
, then check if video.seeking
was true
and don't pause the video.
Like this code:
var video = document.getElementById("videoId");
video.onpause = function() {
if(video.seeking) {
return
}
//else your action for pausing video :)
};
Upvotes: 0
Reputation: 41
@Jason Aller & @Qamer Sayeed are right. If the user hits the pause button the ready state is 4.
In case of seeking, have an onpause
listener for your video and inside that, check if the vid.readyState
is 4(manually clicked!) otherwise if the pause event was initiated by the seek, the vid.readyState
is 1.
Hope this helps!
Upvotes: 4
Reputation: 111
You can use video element's readyState
property to check whether the pause event fired when the user seeked or when the user paused.
var vid = document.getElementById("myVideo");
var vidState = vid.readyState; //when user hit the pause button, this value will be 4
Upvotes: 8
Reputation: 3724
I'd suggest you read though the HTML5 spec to understand how events work when seeking: https://www.w3.org/TR/2011/WD-html5-20110113/video.html#seeking
Without a code sample it is hard to diagnose, but you could try testing the seeking
event during your pause handler.
Upvotes: 3