How to know through JavaScript when the user starts or stops a video?
On a pa开发者_高级运维ge with an embedded Flash video (from YouTube in an <iframe/>
), is it possible to be notified through JavaScript when the user starts or stops playing a video?
As far as I know, events raised on Flash level are not propagated to the container page, so it is not possible to do that. Am I missing something?
YouTube JavaScript Player API Reference
If the player is in an iframe you will have no access to it due to the same origin policy If you can, you should embed the player directly in your page and look for what you need in the api.
A quick glance found this:
function onYouTubePlayerReady(playerId) {
ytplayer = document.getElementById("myytplayer");
ytplayer.addEventListener("onStateChange", "onytplayerStateChange");
}
function onytplayerStateChange(newState) {
alert("Player's new state: " + newState);
}
You could use ExternalInterface within Flash to call a javascript function each time the user starts or stops the video.
You can use youtube api for manipulating movie, For example: make some overlay that will control movie, by capturing click events.
精彩评论