Accessing HTML 5 Video Progress Event with jQuery

六月ゝ 毕业季﹏ 提交于 2019-11-29 03:51:31
RobertPitt

Why not just use:

    $('video#test-vid').bind("progress",function(e){
        console.log(e.total + ' ' + e.loaded + ' ' + e.lengthComputable );
    });

This should work, jQuery should bind the events

Take a look here

HTML5 <video> callbacks?

you get an undefined because jQuery uses a whitelist of event-properties, to normalize events, neither loaded nor total is in this list.

If you want to get the information, you have to use: e.originalEvent.lengthComputable etc..

But honestly you shouldn't do this. This event properties are firefox only and aren't part of the html5 spec anymore. You have to use the buffered object in other browsers. The progress-thing is really problematic in html5 mediaelements. safari on iPad works different from safari on mac and so on.

a cross-browser implementation of a progress-event can be found in the jMediaelement-libary: http://github.com/aFarkas/jMediaelement/blob/1.1.3/src/mm.base-api.js#L312

regards alex

Use the originalEvent:

if(e.originalEvent.lengthComputable && e.originalEvent.total){
     var loaded = e.originalEvent.loaded / e.originalEvent.total * 100;
}

A few wild guesses...

You have:

var vid = $('#test-vid');
$(vid).bind(...

On that second line, vid is already a jQuery object. Have you tried simply using vid.bind()?

Alternatively, if you know addEventListener works, why not use it? Maybe you'll have luck if, after selecting with jQuery, you emit the undecorated DOM object:

var vid = $('#test-vid');
vid.get().addEventListener(...
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!