Created
November 2, 2012 00:59
-
-
Save robby/3997976 to your computer and use it in GitHub Desktop.
html 5 video events
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 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