| <!-- This is a test html file for Youtube video tests --> |
| <html> |
| |
| <script type="text/javascript" src="swfobject.js"></script> |
| <script type="text/javascript"> |
| |
| // Most of this was borrowed from: |
| // http://code.google.com/apis/ajax/playground/?exp=youtube#polling_the_player |
| |
| // Update a particular HTML element with a new value |
| function updateHTML(elmId, value) { |
| document.getElementById(elmId).innerHTML = value; |
| } |
| |
| // This function is called when the player changes state |
| function onPlayerStateChange(newState) { |
| updateHTML("playerState", newState); |
| } |
| |
| // Display information about the current state of the player |
| function updatePlayerInfo() { |
| if(ytplayer && ytplayer.getDuration) { |
| updateHTML("bytesTotal", ytplayer.getVideoBytesTotal()); |
| updateHTML("startBytes", ytplayer.getVideoStartBytes()); |
| updateHTML("bytesLoaded", ytplayer.getVideoBytesLoaded()); |
| updateHTML("duration", ytplayer.getDuration()); |
| updateHTML("videoCurrentTime", ytplayer.getCurrentTime()); |
| } |
| } |
| |
| function onYouTubePlayerReady(playerId) { |
| ytplayer = document.getElementById("myytplayer"); |
| console.log("player ready to play"); |
| setInterval(updatePlayerInfo, 1000); |
| updatePlayerInfo(); |
| // Possible player statuses: |
| // unstarted (-1), ended (0), playing (1), paused (2), buffering (3), |
| // video cued (5). |
| updateHTML("playerState", ytplayer.getPlayerState()); |
| ytplayer.addEventListener("onStateChange", "onPlayerStateChange"); |
| ytplayer.addEventListener("onError", "onPlayerError"); |
| } |
| |
| function loadPlayer() { |
| var params = { allowScriptAccess: "always" }; |
| var atts = { id: "myytplayer" }; |
| var video_id = window.location.href.split("video="); |
| swfobject.embedSWF( |
| "http://www.youtube.com/e/" + video_id[1] + |
| "?version=3&enablejsapi=1&playerapiid=ytplayer", |
| "ytapiplayer", "800", "600", "8", null, null, params, atts); |
| } |
| |
| </script> |
| |
| <div id="ytapiplayer"> |
| You need Flash player 8+ and JavaScript enabled to view this video. |
| </div> |
| <body onload="loadPlayer()"> |
| <br> |
| Player State (playerState): <span id=playerState>0</span> Possible player |
| statuses: unstarted (-1), ended (0), playing (1), paused (2), buffering (3), video cued (5). |
| <br> |
| Total Bytes (bytesTotal): <span id=bytesTotal>0</span> |
| <br> |
| Start Bytes (startBytes): <span id=startBytes>0</span> |
| <br> |
| Bytes Loaded (bytesLoaded): <span id=bytesLoaded>1</span> |
| <br> |
| Duration (duration): <span id=duration>0</span> |
| <br> |
| Current Time (videoCurrentTime): <span id=videoCurrentTime>0</span> |
| |
| </html> |