1 <!-- This is a test html file for Youtube video tests -->
4 <script type=
"text/javascript" src=
"swfobject.js"></script>
5 <script type=
"text/javascript">
7 // Most of this was borrowed from:
8 // http://code.google.com/apis/ajax/playground/?exp=youtube#polling_the_player
10 // Update a particular HTML element with a new value
11 function updateHTML(elmId
, value
) {
12 document
.getElementById(elmId
).innerHTML
= value
;
15 // This function is called when the player changes state
16 function onPlayerStateChange(newState
) {
17 updateHTML("playerState", newState
);
20 // Display information about the current state of the player
21 function updatePlayerInfo() {
22 if(ytplayer
&& ytplayer
.getDuration
) {
23 updateHTML("bytesTotal", ytplayer
.getVideoBytesTotal());
24 updateHTML("startBytes", ytplayer
.getVideoStartBytes());
25 updateHTML("bytesLoaded", ytplayer
.getVideoBytesLoaded());
26 updateHTML("duration", ytplayer
.getDuration());
27 updateHTML("videoCurrentTime", ytplayer
.getCurrentTime());
31 function onYouTubePlayerReady(playerId
) {
32 ytplayer
= document
.getElementById("myytplayer");
33 console
.log("player ready to play");
34 setInterval(updatePlayerInfo
, 1000);
36 // Possible player statuses:
37 // unstarted (-1), ended (0), playing (1), paused (2), buffering (3),
39 updateHTML("playerState", ytplayer
.getPlayerState());
40 ytplayer
.addEventListener("onStateChange", "onPlayerStateChange");
41 ytplayer
.addEventListener("onError", "onPlayerError");
44 function loadPlayer() {
45 var params
= { allowScriptAccess
: "always" };
46 var atts
= { id
: "myytplayer" };
47 var video_id
= window
.location
.href
.split("video=");
49 "http://www.youtube.com/e/" + video_id
[1] +
50 "?version=3&enablejsapi=1&playerapiid=ytplayer",
51 "ytapiplayer", "800", "600", "8", null, null, params
, atts
);
56 <div id=
"ytapiplayer">
57 You need Flash player
8+ and JavaScript enabled to view this video.
59 <body onload=
"loadPlayer()">
61 Player State (playerState):
<span id=playerState
>0</span> Possible player
62 statuses: unstarted (-
1), ended (
0), playing (
1), paused (
2), buffering (
3), video cued (
5).
64 Total Bytes (bytesTotal):
<span id=bytesTotal
>0</span>
66 Start Bytes (startBytes):
<span id=startBytes
>0</span>
68 Bytes Loaded (bytesLoaded):
<span id=bytesLoaded
>1</span>
70 Duration (duration):
<span id=duration
>0</span>
72 Current Time (videoCurrentTime):
<span id=videoCurrentTime
>0</span>