HTML 5视频js更新源并在加载后播放

时间:2013-10-22 14:27:34

标签: javascript html5 video video.js

我正在尝试使用Video.js更改HTML 5视频的来源。

来源正在改变,我可以点击播放,它会播放视频,但我需要视频才能播放。特别是loadedalldata事件。

我已经阅读了api documentation并且它表明,我所做的事情应该有效(根据我的理解。)。

Javascript:

var player = _V_('video'),
    video = [{
        "type": "video\/mp4",
        "src": "http:\/\/mabuse.dev\/assets\/videos\/testVideo.mp4"
    }, {
        "type": "video\/webm",
        "src": "http:\/\/mabuse.dev\/assets\/videos\/testVideo.webm"
    }, {
        "type": "video\/ogg",
        "src": "http:\/\/mabuse.dev\/assets\/videos\/testVideo.ogv"
    }, {
        "type": "video\/flv",
        "src": "http:\/\/mabuse.dev\/assets\/videos\/testVideo.flv"
    }];

/* Add sources to new player */
player.src(video);

/* Remove loader & play video once loaded */
player.on("loadedalldata", function(){
    console.log('test');
    //app.player.play();
});

HTML:

<video class="video-js" id="video" controls preload="none" width="572" height="356" data-setup="{}"></video>

1 个答案:

答案 0 :(得分:1)

尝试收听直接从视频元素发送的类似事件。

document.querySelector("#video").addEventListener("canplaythrough", onLoaded)