4 <title>preload test
</title>
5 <meta name=
"viewport" content=
"width=device-width">
6 <style type=
"text/css" media=
"screen">
7 body { font-family: georgia, serif; background: gray; }
8 video { background: yellow; }
9 .info { background-color:#e3e3f3; padding:
10px; border:
1px solid #
9c9; width:
600px; }
10 .info table { background: #fff; width:
600px; }
11 .info td { border:
1px solid; border-color:#fff #bbb #bbb #fff; background-color:#fff; padding:
2px; font-size:
.7em; width:
50%;}
12 #event_log { background: #fff; font-size:
.5em; width:
100%; }
13 #refresh { margin-top:
10px; }
17 document
.addEventListener('loadedmetadata', querymovie
);
18 document
.addEventListener('waiting', querymovie
);
19 document
.addEventListener('error', querymovie
);
20 document
.addEventListener('durationchange', querymovie
);
21 document
.addEventListener('error', querymovie
);
22 document
.addEventListener('stalled', querymovie
);
23 document
.addEventListener('canplay', querymovie
);
26 var events
= ["abort", "beforeload", "canplay", "canplaythrough", "durationchange", "emptied", "ended", "error", "loadeddata", "loadedmetadata", "loadstart", "pause", "play", "playing", "progress", "ratechange", "seeked", "seeking", "stalled", "suspend", "timeupdate", "volumechange", "waiting", "webkitbeginfullscreen", "webkitendfullscreen"];
27 for (var i
=0; i
< events
.length
; i
++)
28 document
.addEventListener(events
[i
], logProgress
, true);
30 function printTimeRangeValue(element
, prop
)
34 if (prop
== 'Max time buffered')
35 range
= element
.buffered
;
36 else if (prop
== "Max time seekable")
37 range
= element
.seekable
;
44 return range
.start(0).toFixed(2) + ".." + range
.end(0).toFixed(2) + " [length =" + range
.length
+ "]";
45 return "[range length = " + range
.length
+ "]";
48 function statePropertyValue(element
, prop
)
50 var readyNames
= ['HAVE_NOTHING', 'HAVE_METADATA', 'HAVE_CURRENT_DATA', 'HAVE_FUTURE_DATA', 'HAVE_ENOUGH_DATA'];
51 var networkNames
= ['NETWORK_EMPTY', 'NETWORK_IDLE', 'NETWORK_LOADING', 'NETWORK_LOADED', 'NETWORK_NO_SOURCE'];
54 if (prop
== 'Ready State')
55 value
= readyNames
[element
.readyState
];
57 value
= networkNames
[element
.networkState
];
61 function querymovie(evt
)
66 ["Current Source", "currentSrc"],
67 ["Duration", "duration"],
68 ["Video Width", "videoWidth"],
69 ["Video Height", "videoHeight"],
70 ["Default Playback Rate", "defaultPlaybackRate"],
72 ["Preload", "preload"],
73 ["Ready State", statePropertyValue
],
74 ["Network State", statePropertyValue
],
75 ["Max time buffered", printTimeRangeValue
],
76 ["Max time seekable", printTimeRangeValue
]
79 var vid
= evt
? evt
.target
: document
.getElementById('vid');
80 for (var i
= 0; i
< movieProperties
.length
; i
++)
82 var prop
= movieProperties
[i
];
85 if (typeof prop
[1] == 'function')
86 val
= prop
[1](vid
, prop
[0]);
90 if (typeof val
== 'number')
92 else if (typeof val
== "undefined")
94 document
.getElementById(prop
[0]).innerHTML
= val
;
100 var vid
= document
.getElementById("vid");
102 logMsg(vid
, "###############");
103 logMsg(vid
, "##### setting url to " + url
);
113 var now
= new Date();
114 var hour
= now
.getHours();
115 var minute
= now
.getMinutes();
116 var second
= now
.getSeconds();
117 var milli
= now
.getMilliseconds();
125 minute
= "0" + minute
;
127 second
= "0" + second
;
129 milli
= "00" + milli
;
130 else if (milli
< 100)
133 return hour
+ ':' + minute
+ ':' + second
+ '.' + milli
;
136 function logMsg(vid
, msg
)
138 document
.getElementById('event_log').value
+= clockTime() + " - " + msg
+ ' \r';
143 document
.getElementById('event_log').value
= '';
146 function logProgress(ev
)
150 if (ev
.type
== 'timeupdate')
152 var logTimeupdate
= document
.getElementById('log-timeupdate');
153 if (!logTimeupdate
.checked
)
156 if (ev
.type
== 'progress')
158 var logTimeupdate
= document
.getElementById('log-progress');
159 if (!logTimeupdate
.checked
)
163 logMsg(vid
, ev
.type
+ ' (time = ' + vid
.currentTime
.toFixed(2) + ')');
166 function logError(ev
)
169 logMsg(vid
, "vid.error = " + vid
.error
.code
);
173 function preload(value
)
175 var vid
= document
.getElementById("vid");
176 var old
= vid
.preload
;
184 <body onload=
"querymovie()">
186 <video id=
"vid" src=
"http://trailers.apple.com/movies/weinstein/submarine/submarine-tlr1_480p.mov" height=
"391"
187 controls
preload=
"metadata">
191 <button id=
"controls" onclick=
"preload('none')">preload=none
</button>
192 <button id=
"controls" onclick=
"preload('metadata')">preload=metadata
</button>
193 <button id=
"controls" onclick=
"preload('auto')">preload=auto
</button>
197 <input id=
"querymovie" type=
"button" value=
"Refresh" onclick=
"querymovie()">
201 <tr><td>Preload
</td><td id=
"Preload"></td></tr>
202 <tr><td>Error
</td><td id=
"Error"></td></tr>
203 <tr><td>Duration
</td> <td id=
"Duration"></td></tr>
204 <tr><td>Video Width
</td><td id=
"Video Width"></td></tr>
205 <tr><td>Video Height
</td><td id=
"Video Height"></td></tr>
206 <tr><td>Default Playback Rate
</td><td id=
"Default Playback Rate"></td></tr>
207 <tr><td>Volume
</td><td id=
"Volume"></td></tr>
208 <tr><td>Ready State
</td><td id=
"Ready State"></td></tr>
209 <tr><td>Network State
</td><td id=
"Network State"></td></tr>
210 <tr><td>Max time buffered
</td><td id=
"Max time buffered"></td></tr>
211 <tr><td>Max time seekable
</td><td id=
"Max time seekable"></td></tr>
212 <tr><td>Source
</td><td id=
"Source"></td></tr>
213 <tr><td>Current Source
</td> <td id=
"Current Source"></td></tr>
220 Enter a url:
<input type=
"text" size=
"90" maxlength=
"2048" onchange=
"setURL(this.value)" >
222 <input id=
"clear_log" type=
"button" value=
"Clear" onclick=
"clearlog()">
223 <input type=
"checkbox" id=
"log-progress"> log 'progress' events
224 <input type=
"checkbox" checked
id=
"log-timeupdate"> log 'timeupdate' events
225 <textarea rows=
30 cols=
30 id=event_log
></textarea>
226 <div id=
"event_log"></div>