Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML 5 video js update source and play once loaded

I am trying to change the source of a HTML 5 video using Video.js.

Source is changing and I can click play and it'll play the video, but I need video to play on an event. Specifically the loadedalldata event.

I've read the api documentation and it suggest, that what I've done should work (From my understanding.).

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>
like image 574
CharliePrynn Avatar asked Oct 22 '13 14:10

CharliePrynn


1 Answers

Try listening to a similar event that is dispatched directly from the video element.

document.querySelector("#video").addEventListener("canplaythrough", onLoaded)
like image 81
posit labs Avatar answered Oct 15 '22 02:10

posit labs