2

我正在尝试创建一个视频,该视频会在您单击按钮后跳转到视频中的某个点后自动播放。我有它,以便视频跳转到现场,但我不知道如何让它从那里自动播放。我是 javascript 新手,我认为可能缺少一个简单的解决方案。

    function Fwd(){
        if (video.currentTime < 17.91 && video.currentTime >= 0)
        { (video.currentTime = 17.92)
        }
        else if (video.currentTime < 35.93 && video.currentTime > 17.91)
        { (video.currentTime = 35.94)
        }
    }

这是我的一些html

<div id="sideright">
  <input type="button" id="fwdButton" onclick="Fwd()" class="button_fwdrew" />
</div>

<video id="video" width="896" height="504" data-setup="{}" >
<source src="video/myAwesomeVideo.mp4" type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"' />
<source src="video/myAwesomeVideo.webmhd.webm" type='video/webm; codecs="vp8, vorbis"'>
<source src="video/myAwesomeVideo.oggtheora.ogv" type='video/ogg; codecs="theora, vorbis"' />
<p>Your browser doesn't support HTML5. Maybe you should upgrade.</p>
</video>

这是我的更多 JavaScript

var v = document.getElementById("video")[0];
    v.volume = .5;
    v.pause();
    video.onpause = video.onplay = function(e) {
    playpause.value = video.paused ? 'Play' : 'Pause';
        }
4

2 回答 2

0

video.play()工作?

function Fwd(){
    var video = document.getElementById("video");
    if (video.currentTime < 17.91 && video.currentTime >= 0)
    { 
        (video.currentTime = 17.92)
    }
    else if (video.currentTime < 35.93 && video.currentTime > 17.91)
    { 
        (video.currentTime = 35.94)
    }
    video.play();
}

我为video变量添加了一个声明,因为这似乎引起了一些混乱。

在您的编辑中,您创建了一个v变量,但您已经为它分配了与元素关联的 DOM 对象的第一个属性或方法的值idvideo这是数组访问[0]器在 之后所做的document.getElementById("video"))。几乎可以肯定,该属性或方法本身不会有属性volume或方法pause()。之后,您已经开始使用video变量而没有明显定义它或设置它的值。它可能是在您尚未发布的代码中定义的,但从您所展示的内容来看,这将是一种浪费,因为您显然试图使v变量成为对视频元素的引用 - 不需要两者vvideo.

决定一个变量来保存您对视频元素的引用,使用它分配它document.getElementById("video"),然后一致地使用它。

于 2013-01-03T18:17:09.067 回答
0
var update = function() {
    if (document.getElementById("video").currentTime < 10) 
    {
        document.getElementById("video").currentTime = 10;
    }
};
document.getElementById("video").setAttribute("ontimeupdate", "update();");
document.getElementById("video").play();
于 2013-11-19T15:08:16.653 回答