如果视频 = 持续时间则停止并快退

发布于 2024-10-31 09:19:36 字数 491 浏览 2 评论 0原文

我正在制作一个 HTML5 视频播放器。我想要它,以便当电影停止播放时这些执行

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

我尝试过,但它不起作用

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

}

有人找到了这个问题的解决方案吗? 问题 = 我缺乏 JavaScript 知识

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 work

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

聆听风音 2024-11-07 09:19:36

查看以下问题和答案:

HTML5

我会指定一个回调在视频实际结束时执行,如下所示:

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

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

您还表示,当媒体“停止”时您想暂停视频,您能描述一下您这样做的动机吗?

议程上的下一个是视频重置,看起来您想将媒体的位置设置为开始,如果媒体停止,您必须首先确保您确定视频尚未暂停,就像您所做的那样如果用户已经去煮咖啡了,不想重置位置。

如果您只想在电影实际结束时设置媒体位置,那么这将毫无意义(除非您有充分的理由这样做),毫无意义的原因是当用户在电影结束后单击播放时, html5 媒体播放器的默认操作是将位置设置为 0。

上述解决方案应该完全适合您。

我建议使用 Kaltura HTML5 视频库来帮助您管理媒体播放器。

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.

染火枫林 2024-11-07 09:19:36

首先,您只需在 video.ending 上设置一个条件即可检查视频是否已结束。然后您可以使用 this.currentTime(0); 设置时间

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);

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文