Created
April 6, 2017 16:47
-
-
Save evitolins/a84cf3f34ee8c344a51a893207c34054 to your computer and use it in GitHub Desktop.
Attach alerts for every video event available.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var video_events = { | |
'abort' : 'abort : The loading of an audio/video is aborted', | |
'canplay' : 'canplay : The browser can start playing the audio/video', | |
'canplaythrough' : 'canplaythrough : The browser can play through the audio/video without stopping for buffering', | |
'durationchange' : 'durationchange : The duration of the audio/video is changed', | |
'emptied' : 'emptied : The current playlist is empty', | |
'ended' : 'ended : The current playlist is ended', | |
'error' : 'error : An error occurred during the loading of an audio/video', | |
'loadeddata' : 'loadeddata : The browser has loaded the current frame of the audio/video', | |
'loadedmetadata' : 'loadedmetadata : The browser has loaded meta data for the audio/video', | |
'loadstart' : 'loadstart : The browser starts looking for the audio/video', | |
'pause' : 'pause : The audio/video has been paused', | |
'play' : 'play : The audio/video has been started or is no longer paused', | |
'playing' : 'playing : The audio/video is playing after having been paused or stopped for buffering', | |
'progress' : 'progress : The browser is downloading the audio/video', | |
'ratechange' : 'ratechange : The playing speed of the audio/video is changed', | |
'seeked' : 'seeked : The user is finished moving/skipping to a new position in the audio/video', | |
'seeking' : 'seeking : The user starts moving/skipping to a new position in the audio/video', | |
'stalled' : 'stalled : The browser is trying to get media data, but data is not available', | |
'suspend' : 'suspend : The browser is intentionally not getting media data', | |
'timeupdate' : 'timeupdate : The current playback position has changed', | |
'volumechange' : 'volumechange : The volume has been changed', | |
'waiting' : 'waiting : The video stops because it needs to buffer the next frame' | |
} | |
var listeners = {}; | |
var v = document.getElementsByTagName('video')[0]; | |
Object.keys(listeners).map(function(key){ | |
v.removeEventListener(key, listeners[key]); | |
}); | |
// Add all listeners | |
Object.keys(video_events).map(function(key){ | |
listeners[key] = function () { console.log(video_events[key]); }; | |
v.addEventListener(key, listeners[key]); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment