玩 html5 视频,想知道是否有办法在它发生时列出它的事件。
我有一个结束 - myVideo.addEventListener('ended',videoEnded,false);
哪个工作正常,但我如何创建一个监听器来监听每个事件并命名它们?
myVideo.addEventListener('ALL',AddToLog,false);
function AddToLog(){
console.log(eventname);
}
欢迎任何指点。
丹.
最佳答案
订阅所有<video>
或 <audio>
一次事件:
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);
});
研究来自the specification 的媒体事件列表也是一个好主意。 .
多个事件监听器学分转到 @RobG's solution .
关于events - 收听所有 html 视频事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7765410/