开发者

If video = duration stop and rewind

开发者 https://www.devze.com 2023-02-23 01:37 出处:网络
I\'m making a HTML5 video player. I want it so that when the movie stops the play these executes video.pause();

I'm making a HTML5 video player. I want it so that when the movie stops the play these executes

video.pause();
video.currentTime=0;
document.getElementById('message').innerHTML="Finished";

I tried this but it didn't w开发者_Go百科ork

function rewsi() {
var video = document.getElementsByTagName('video')[0];
if (video.currentTime==video.duration) {
    video.pause();
    video.currentTime=0;
    document.getElementById('message').innerHTML="Finished";
}

}

Anyone got a solution for this problem? Problem = My lack of knowledge in JavaScript


Looking at the following question and asnwer:

HTML5 <video> callbacks?

I would assign a callback to be executed when the video has actually ended like so:

var Media = document.getElementsByTagName('video')[0];
var Message = document.getElementById('message');

Media.bind('ended',function(){
     Message.innerHTML = "The media file has completed";
});

You also stated that when the media 'stops' you want to pause the video, can you describe your motives for doing that ?

The next on the agenda is the video resetting as such, looks like you want to set the position of the media to the start if the media stops, you must first make sure that your determining that the video has not been paused, as you do not want to reset the position if the user has gone to make a cup of coffee.

If you only want to set the media position when the movie has actually ended then this would be pointless (unless you have a valid reason to do so), the reason it would be pointless is that when the user clicks play after it has ended, the default action html5 media player takes is to set the position to 0.

The above solution should work out exactly right for you.

i will recommend using Kaltura HTML5 Video Library to help you manage the media player.


First, you can check if the video has ended by simply putting a condition on video.ended. Then you can set the time with this.currentTime(0);

0

精彩评论

暂无评论...
验证码 换一张
取 消