开发者

Listen to all html video events

开发者 https://www.devze.com 2023-04-12 19:23 出处:网络
Playing around with html5 video and was wondering if there was a way to list its events as it happens.

Playing around with html5 video and was wondering if there was a way to list its events as it happens.

I have one for ended - myVideo.addEventListener('ended',videoEnded,false);

Which works fine but how can 开发者_如何学Pythoni create a a listener which will listen to every event and name them?

myVideo.addEventListener('ALL',AddToLog,false);
function AddToLog(){
   console.log(eventname);
}

Any pointers welcome.

Dan.


Subscribe to all <video> or <audio> events at once:

function addListenerMulti(el, s, fn) {
    s.split(' ').forEach(e => el.addEventListener(e, fn, false));
}

var video = document.getElementById('myVideo');

addListenerMulti(video, 'abort canplay canplaythrough durationchange emptied encrypted ended error interruptbegin interruptend loadeddata loadedmetadata loadstart mozaudioavailable pause play playing progress ratechange seeked seeking stalled suspend timeupdate volumechange waiting', function(e){
    console.log(e.type);
});

It's also a good idea to study media events list from the specification.

Multiple events listener credits go to @RobG's solution.


You can't. You need to listen to specific events.

You can find a list of possibly available events from the specification

0

精彩评论

暂无评论...
验证码 换一张
取 消