This works for Vimeo ... Triggers a javascript warning on the "Play" event, but there are a number of other events, such as "finished", "pause", "playProgress" (constantly updated during video playback). Uses jQuery
$(document).ready( function () { var f = $('iframe'), url = f.attr('src').split('?')[0], status = $('.status'); // 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); switch (data.event) { case 'ready': onReady(); break; case 'play': onPlay(); break; } } // Call the API when a button is pressed $('button').on('click', function() { post($(this).text().toLowerCase()); }); // 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), url); } function onReady() { status.text('ready'); post('addEventListener', 'play'); } function onPlay() { alert("Dude done clicked 'Play'"); } });
colmde
source share