Skip to content

Instantly share code, notes, and snippets.

@robby
Created November 2, 2012 00:59
Show Gist options
  • Save robby/3997976 to your computer and use it in GitHub Desktop.
Save robby/3997976 to your computer and use it in GitHub Desktop.
html 5 video events
var f = $('#videoFrame');
// Listen for messages from the player
if (window.addEventListener){
window.addEventListener('message', onMessageReceived, false);
}
else {
window.attachEvent('onmessage', onMessageReceived, false);
}
// Handle messages received from the player
function onMessageReceived(e) {
var data = JSON.parse(e.data);
({
ready: function(){
post('addEventListener', 'finish');
post('addEventListener', 'playProgress');
},
finish: function(){
alert('done.');
},
playProgress: function(data){
console.log(data.seconds);
}
}[data.event] || $.noop)(data);
}
// Helper function for sending a message to the player
function post(action, value) {
var data = { method: action };
if (value) {
data.value = value;
}
f[0].contentWindow.postMessage(JSON.stringify(data), '*');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment