Commit 0b534e9a authored by Daniel Amm's avatar Daniel Amm Committed by Jean-Baptiste Kempf

test pages: JavaScript indenting, cleanup and improving

Signed-off-by: Jean-Baptiste Kempf's avatarJean-Baptiste Kempf <jb@videolan.org>
parent a96a6ca2
...@@ -4,17 +4,18 @@ ...@@ -4,17 +4,18 @@
<title>Simplest VLC plugin test</title> <title>Simplest VLC plugin test</title>
<script type="text/javascript"> <script type="text/javascript">
function play(tgt) { function play(tgt)
{
var uri = "http://streams.videolan.org/streams/mp4/Mr_MrsSmith-h264_aac.mp4"; var uri = "http://streams.videolan.org/streams/mp4/Mr_MrsSmith-h264_aac.mp4";
if (document.all) tgt += "_IE" if (document.all) tgt += "_IE"
var tgt = document.getElementById(tgt); var vlc = document.getElementById(tgt);
// alert(tgt); // alert(vlc);
if (document.all) tgt.playlist.add(uri,uri, new Array()); vlc.playlist.add(uri);
else tgt.playlist.add(uri,uri, ""); vlc.playlist.play();
tgt.playlist.play();
} }
function reload() { function reload()
document.body.innerHTML=""; {
document.body.innerHTML = "";
setTimeout("document.location.reload();", 500); setTimeout("document.location.reload();", 500);
} }
</script> </script>
......
...@@ -13,7 +13,7 @@ form { ...@@ -13,7 +13,7 @@ form {
<!-- <!--
function init() function init()
{ {
if( navigator.appName.indexOf("Microsoft Internet")==-1 ) if( navigator.appName.indexOf("Microsoft Internet") == -1 )
{ {
onVLCPluginReady() onVLCPluginReady()
} }
...@@ -24,7 +24,7 @@ function init() ...@@ -24,7 +24,7 @@ function init()
else else
{ {
/* Explorer loads plugins asynchronously */ /* Explorer loads plugins asynchronously */
document.onreadystatechange=function() document.onreadystatechange = function()
{ {
if( document.readyState == 'complete' ) if( document.readyState == 'complete' )
{ {
...@@ -36,16 +36,16 @@ function init() ...@@ -36,16 +36,16 @@ function init()
function getVLC(name) function getVLC(name)
{ {
if (window.document[name]) if( window.document[name] )
{ {
return window.document[name]; return window.document[name];
} }
if (navigator.appName.indexOf("Microsoft Internet")==-1) if( navigator.appName.indexOf("Microsoft Internet") == -1 )
{ {
if (document.embeds && document.embeds[name]) if( document.embeds && document.embeds[name] )
return document.embeds[name]; return document.embeds[name];
} }
else // if (navigator.appName.indexOf("Microsoft Internet")!=-1) else
{ {
return document.getElementById(name); return document.getElementById(name);
} }
...@@ -55,16 +55,17 @@ function registerVLCEvent(event, handler) ...@@ -55,16 +55,17 @@ function registerVLCEvent(event, handler)
{ {
var vlc = getVLC("vlc"); var vlc = getVLC("vlc");
if (vlc) { if( vlc )
if (vlc.attachEvent) { {
if( vlc.attachEvent )
{
// Microsoft // Microsoft
vlc.attachEvent (event, handler); vlc.attachEvent(event, handler);
} else if (vlc.addEventListener) { }
else if( vlc.addEventListener )
{
// Mozilla: DOM level 2 // Mozilla: DOM level 2
vlc.addEventListener (event, handler); vlc.addEventListener(event, handler, false);
} else {
// DOM level 0
eval("vlc.on" + event + " = handler");
} }
} }
} }
...@@ -73,16 +74,17 @@ function unregisterVLCEvent(event, handler) ...@@ -73,16 +74,17 @@ function unregisterVLCEvent(event, handler)
{ {
var vlc = getVLC("vlc"); var vlc = getVLC("vlc");
if (vlc) { if( vlc )
if (vlc.detachEvent) { {
if( vlc.detachEvent )
{
// Microsoft // Microsoft
vlc.detachEvent (event, handler); vlc.detachEvent(event, handler);
} else if (vlc.removeEventListener) { }
else if( vlc.removeEventListener )
{
// Mozilla: DOM level 2 // Mozilla: DOM level 2
vlc.removeEventListener (event, handler); vlc.removeEventListener(event, handler, false);
} else {
// DOM level 0
eval("vlc.on" + event + " = null");
} }
} }
} }
...@@ -283,9 +285,9 @@ function close() ...@@ -283,9 +285,9 @@ function close()
--> -->
<div id="inputTrackerDiv"></div> <div id="inputTrackerDiv"></div>
</td> </td>
<td style="width:15%; text-align:center"> <td style="width:100px; text-align:center">
<div id="info">-:--:--/-:--:--</div> <div id="info">-:--:--/-:--:--</div>
<div id="state">Stopped...</div> <div id="state">Idle...</div>
</td> </td>
</tr> </tr>
</table> </table>
...@@ -293,7 +295,7 @@ function close() ...@@ -293,7 +295,7 @@ function close()
</tr> </tr>
<tr> <tr>
<td> <td>
<input type="button" id="PlayOrPause" value=" Play " onClick='doPlayOrPause();'> <input type="button" id="PlayOrPause" style="width:60px" value="Play" onClick='doPlayOrPause();'>
<input type="button" value="Stop" onClick='doStop();'> <input type="button" value="Stop" onClick='doStop();'>
&nbsp; &nbsp;
<input type="button" value=" << " onClick='doPlaySlower();'> <input type="button" value=" << " onClick='doPlaySlower();'>
...@@ -308,7 +310,7 @@ function close() ...@@ -308,7 +310,7 @@ function close()
<span style="text-align:center">Volume:</span> <span style="text-align:center">Volume:</span>
<input type="button" value=" - " onClick='updateVolume(-10)'> <input type="button" value=" - " onClick='updateVolume(-10)'>
<span id="volumeTextField" style="text-align:center">--</span> <span id="volumeTextField" style="text-align:center">--</span>
<input type="button" value=" + " onClick='updateVolume(+10)'> <input type="button" value=" + " onClick='updateVolume(10)'>
<input type="button" value="Mute" onClick='getVLC("vlc").audio.toggleMute();'> <input type="button" value="Mute" onClick='getVLC("vlc").audio.toggleMute();'>
</td> </td>
</tr> </tr>
...@@ -328,7 +330,7 @@ function close() ...@@ -328,7 +330,7 @@ function close()
</select> </select>
</td> </td>
<td style="text-align:right"> <td style="text-align:right">
<input type="button" id="itemCount" value="Items 0" onClick='doItemCount();'> <input type="button" id="itemCount" value="Items: 0" onClick='doItemCount();'>
<form action="javascript:doRemoveItem(document.getElementById('removeid').value);"> <form action="javascript:doRemoveItem(document.getElementById('removeid').value);">
<input type="text" size="4" value="" id="removeid"> <input type="text" size="4" value="" id="removeid">
<input type="submit" value="Delete"> <input type="submit" value="Delete">
...@@ -442,8 +444,6 @@ function close() ...@@ -442,8 +444,6 @@ function close()
<script type="text/javascript"> <script type="text/javascript">
<!-- <!--
var rate = 0;
var prevState = 0;
var telxState = false; var telxState = false;
var canPause = true; var canPause = true;
var canSeek = true; var canSeek = true;
...@@ -472,7 +472,7 @@ function doGetPosition() ...@@ -472,7 +472,7 @@ function doGetPosition()
var vlc = getVLC("vlc"); var vlc = getVLC("vlc");
// set slider to new position // set slider to new position
if (vlc) if( vlc )
alert( "position is " + vlc.input.time); alert( "position is " + vlc.input.time);
} }
...@@ -531,7 +531,7 @@ function doToggleTeletext() ...@@ -531,7 +531,7 @@ function doToggleTeletext()
if( vlc ) if( vlc )
{ {
vlc.video.toggleTeletext(); vlc.video.toggleTeletext();
if (telxState) if( telxState )
{ {
document.getElementById("telx").innerHTML = "Teletext on"; document.getElementById("telx").innerHTML = "Teletext on";
telxState = true; telxState = true;
...@@ -550,7 +550,7 @@ function doItemCount() ...@@ -550,7 +550,7 @@ function doItemCount()
if( vlc ) if( vlc )
{ {
var count = vlc.playlist.items.count; var count = vlc.playlist.items.count;
document.getElementById("itemCount").value = " Items " + count + " "; document.getElementById("itemCount").value = " Items: " + count + " ";
} }
} }
...@@ -567,10 +567,6 @@ function doPlaylistClearAll() ...@@ -567,10 +567,6 @@ function doPlaylistClearAll()
if( vlc ) if( vlc )
{ {
vlc.playlist.items.clear(); vlc.playlist.items.clear();
while( vlc.playlist.items.count > 0)
{
// wait till playlist empties.
}
doItemCount(); doItemCount();
} }
} }
...@@ -615,45 +611,40 @@ function doState() ...@@ -615,45 +611,40 @@ function doState()
if( vlc ) if( vlc )
newState = vlc.input.state; newState = vlc.input.state;
if( newState == 0 ) switch( newState )
{ {
// current media has stopped case 0:
// player is in idle state
onEnd(); onEnd();
} break;
else if( newState == 1 ) case 1:
{
// current media is openning/connecting // current media is openning/connecting
onOpen(); onOpen();
} break;
else if( newState == 2 ) case 2:
{
// current media is buffering data // current media is buffering data
onBuffer(); onBuffer();
} break;
else if( newState == 3 ) case 3:
{
// current media is now playing // current media is now playing
onPlay(); onPlay();
} break;
else if( newState == 4 ) case 4:
{
// current media is now paused // current media is now paused
onPause(); onPause();
} break;
else if( newState == 5 ) case 5:
{
// current media has stopped // current media has stopped
onStop(); onStop();
} break;
else if( newState == 6 ) case 6:
{
// current media has ended // current media has ended
onEnd(); onEnd();
} break;
else if( newState == 7 ) case 7:
{
// current media encountered error // current media encountered error
onError(); onError();
break;
} }
} }
...@@ -666,14 +657,8 @@ function doGo(targetURL) ...@@ -666,14 +657,8 @@ function doGo(targetURL)
if( vlc ) if( vlc )
{ {
vlc.playlist.items.clear(); vlc.playlist.items.clear();
while( vlc.playlist.items.count > 0 )
{
// clear() may return before the playlist has actually been cleared
// just wait for it to finish its job
}
var options = [":rtsp-tcp"]; var options = [":rtsp-tcp"];
var itemId = vlc.playlist.add(targetURL,"",options); var itemId = vlc.playlist.add(targetURL,"",options);
options = [];
if( itemId != -1 ) if( itemId != -1 )
{ {
// play MRL // play MRL
...@@ -694,7 +679,6 @@ function doAdd(targetURL) ...@@ -694,7 +679,6 @@ function doAdd(targetURL)
if( vlc ) if( vlc )
{ {
vlc.playlist.add(targetURL, "", options); vlc.playlist.add(targetURL, "", options);
options = [];
doItemCount(); doItemCount();
} }
} }
...@@ -732,27 +716,39 @@ function doPlayFaster() ...@@ -732,27 +716,39 @@ function doPlayFaster()
function doMarqueeOption(option, value) function doMarqueeOption(option, value)
{ {
var vlc = getVLC("vlc"); var vlc = getVLC("vlc");
val = parseInt(value);
if( vlc ) if( vlc )
{ {
if (option == 1) val = parseInt(value);
switch( option )
{
case "1":
vlc.video.marquee.color = val; vlc.video.marquee.color = val;
if (option == 2) break;
case "2":
vlc.video.marquee.opacity = val; vlc.video.marquee.opacity = val;
if (option == 3) break;
case "3":
vlc.video.marquee.position = value; vlc.video.marquee.position = value;
if (option == 4) break;
case "4":
vlc.video.marquee.refresh = val; vlc.video.marquee.refresh = val;
if (option == 5) break;
case "5":
vlc.video.marquee.size = val; vlc.video.marquee.size = val;
if (option == 6) break;
case "6":
vlc.video.marquee.text = value; vlc.video.marquee.text = value;
if (option == 7) break;
case "7":
vlc.video.marquee.timeout = val; vlc.video.marquee.timeout = val;
if (option == 8) break;
case "8":
vlc.video.marquee.x = val; vlc.video.marquee.x = val;
if (option == 9) break;
case "9":
vlc.video.marquee.y = val; vlc.video.marquee.y = val;
break;
}
} }
} }
...@@ -761,21 +757,31 @@ function doLogoOption(option, value) ...@@ -761,21 +757,31 @@ function doLogoOption(option, value)
var vlc = getVLC("vlc"); var vlc = getVLC("vlc");
if( vlc ) if( vlc )
{ {
if (option == 1) val = parseInt(value);
switch( option )
{
case "1":
vlc.video.logo.file(value); vlc.video.logo.file(value);
if (option == 2) break;
case "2":
vlc.video.logo.position = value; vlc.video.logo.position = value;
val = parseInt(value); break;
if (option == 3) case "3":
vlc.video.logo.opacity = val; vlc.video.logo.opacity = val;
if (option == 4) break;
case "4":
vlc.video.logo.repeat = val; vlc.video.logo.repeat = val;
if (option == 5) break;
case "5":
vlc.video.logo.delay = val; vlc.video.logo.delay = val;
if (option == 6) break;
case "6":
vlc.video.logo.x = val; vlc.video.logo.x = val;
if (option == 7) break;
case "7":
vlc.video.logo.y = val; vlc.video.logo.y = val;
break;
}
} }
} }
...@@ -832,22 +838,18 @@ function onPlaying() ...@@ -832,22 +838,18 @@ function onPlaying()
function onPause() function onPause()
{ {
document.getElementById("state").innerHTML = "Paused..."; document.getElementById("state").innerHTML = "Paused...";
document.getElementById("PlayOrPause").value = " Play "; document.getElementById("PlayOrPause").value = "Play";
} }
function onStop() function onStop()
{ {
var vlc = getVLC("vlc");
document.getElementById("info").innerHTML = "-:--:--/-:--:--"; document.getElementById("info").innerHTML = "-:--:--/-:--:--";
document.getElementById("state").innerHTML = "Stopped..."; document.getElementById("state").innerHTML = "Stopped...";
document.getElementById("PlayOrPause").value = " Play "; document.getElementById("PlayOrPause").value = "Play";
} }
function onError() function onError()
{ {
var vlc = getVLC("vlc");
document.getElementById("state").innerHTML = "Error..."; document.getElementById("state").innerHTML = "Error...";
} }
......
...@@ -17,7 +17,7 @@ form { ...@@ -17,7 +17,7 @@ form {
<!-- <!--
function init() function init()
{ {
if( navigator.appName.indexOf("Microsoft Internet")==-1 ) if( navigator.appName.indexOf("Microsoft Internet") == -1 )
{ {
onVLCPluginReady() onVLCPluginReady()
} }
...@@ -28,7 +28,7 @@ function init() ...@@ -28,7 +28,7 @@ function init()
else else
{ {
/* Explorer loads plugins asynchronously */ /* Explorer loads plugins asynchronously */
document.onreadystatechange=function() document.onreadystatechange = function()
{ {
if( document.readyState == 'complete' ) if( document.readyState == 'complete' )
{ {
...@@ -40,16 +40,16 @@ function init() ...@@ -40,16 +40,16 @@ function init()
function getVLC(name) function getVLC(name)
{ {
if (window.document[name]) if( window.document[name] )
{ {
return window.document[name]; return window.document[name];
} }
if (navigator.appName.indexOf("Microsoft Internet")==-1) if( navigator.appName.indexOf("Microsoft Internet") == -1 )
{ {
if (document.embeds && document.embeds[name]) if( document.embeds && document.embeds[name] )
return document.embeds[name]; return document.embeds[name];
} }
else // if (navigator.appName.indexOf("Microsoft Internet")!=-1) else
{ {
return document.getElementById(name); return document.getElementById(name);
} }
...@@ -59,16 +59,17 @@ function registerVLCEvent(event, handler) ...@@ -59,16 +59,17 @@ function registerVLCEvent(event, handler)
{ {
var vlc = getVLC("vlc"); var vlc = getVLC("vlc");
if (vlc) { if( vlc )
if (vlc.attachEvent) { {
if( vlc.attachEvent )
{
// Microsoft // Microsoft
vlc.attachEvent (event, handler); vlc.attachEvent(event, handler);
} else if (vlc.addEventListener) { }
else if( vlc.addEventListener )
{
// Mozilla: DOM level 2 // Mozilla: DOM level 2
vlc.addEventListener (event, handler, true); vlc.addEventListener(event, handler, false);
} else {
// DOM level 0
eval("vlc.on" + event + " = handler");
} }
} }
} }
...@@ -77,16 +78,17 @@ function unregisterVLCEvent(event, handler) ...@@ -77,16 +78,17 @@ function unregisterVLCEvent(event, handler)
{ {
var vlc = getVLC("vlc"); var vlc = getVLC("vlc");
if (vlc) { if( vlc )
if (vlc.detachEvent) { {
if( vlc.detachEvent )
{
// Microsoft // Microsoft
vlc.detachEvent (event, handler); vlc.detachEvent(event, handler);
} else if (vlc.removeEventListener) { }
else if( vlc.removeEventListener )
{
// Mozilla: DOM level 2 // Mozilla: DOM level 2
vlc.removeEventListener (event, handler, true); vlc.removeEventListener(event, handler, false);
} else {
// DOM level 0
eval("vlc.on" + event + " = null");
} }
} }
} }
...@@ -162,21 +164,6 @@ function handle_MediaPlayerTimeChanged(time) ...@@ -162,21 +164,6 @@ function handle_MediaPlayerTimeChanged(time)
} }
} }
function handle_MediaPlayerPositionChanged(val)
{
// set javascript slider to correct position
}
function handle_MediaPlayerSeekableChanged(val)
{
setSeekable(val);
}
function handle_MediaPlayerPausableChanged(val)
{
setPauseable(val);
}
function handle_MediaPlayerTitleChanged(val) function handle_MediaPlayerTitleChanged(val)
{ {
//setTitle(val); //setTitle(val);
...@@ -203,9 +190,6 @@ function onVLCPluginReady() ...@@ -203,9 +190,6 @@ function onVLCPluginReady()
registerVLCEvent("MediaPlayerEndReached", handle_MediaPlayerEndReached); registerVLCEvent("MediaPlayerEndReached", handle_MediaPlayerEndReached);
registerVLCEvent("MediaPlayerEncounteredError", handle_MediaPlayerEncounteredError); registerVLCEvent("MediaPlayerEncounteredError", handle_MediaPlayerEncounteredError);
registerVLCEvent("MediaPlayerTimeChanged", handle_MediaPlayerTimeChanged); registerVLCEvent("MediaPlayerTimeChanged", handle_MediaPlayerTimeChanged);
registerVLCEvent("MediaPlayerPositionChanged", handle_MediaPlayerPositionChanged);
registerVLCEvent("MediaPlayerSeekableChanged", handle_MediaPlayerSeekableChanged);
registerVLCEvent("MediaPlayerPausableChanged", handle_MediaPlayerPausableChanged);
registerVLCEvent("MediaPlayerTitleChanged", handle_MediaPlayerTitleChanged); registerVLCEvent("MediaPlayerTitleChanged", handle_MediaPlayerTitleChanged);
registerVLCEvent("MediaPlayerLengthChanged", handle_MediaPlayerLengthChanged); registerVLCEvent("MediaPlayerLengthChanged", handle_MediaPlayerLengthChanged);
} }
...@@ -224,9 +208,6 @@ function close() ...@@ -224,9 +208,6 @@ function close()
unregisterVLCEvent("MediaPlayerEndReached", handle_MediaPlayerEndReached); unregisterVLCEvent("MediaPlayerEndReached", handle_MediaPlayerEndReached);
unregisterVLCEvent("MediaPlayerEncounteredError", handle_MediaPlayerEncounteredError); unregisterVLCEvent("MediaPlayerEncounteredError", handle_MediaPlayerEncounteredError);
unregisterVLCEvent("MediaPlayerTimeChanged", handle_MediaPlayerTimeChanged); unregisterVLCEvent("MediaPlayerTimeChanged", handle_MediaPlayerTimeChanged);
unregisterVLCEvent("MediaPlayerPositionChanged", handle_MediaPlayerPositionChanged);
unregisterVLCEvent("MediaPlayerSeekableChanged", handle_MediaPlayerSeekableChanged);
unregisterVLCEvent("MediaPlayerPausableChanged", handle_MediaPlayerPausableChanged);
unregisterVLCEvent("MediaPlayerTitleChanged", handle_MediaPlayerTitleChanged); unregisterVLCEvent("MediaPlayerTitleChanged", handle_MediaPlayerTitleChanged);
unregisterVLCEvent("MediaPlayerLengthChanged", handle_MediaPlayerLengthChanged); unregisterVLCEvent("MediaPlayerLengthChanged", handle_MediaPlayerLengthChanged);
} }
...@@ -286,12 +267,12 @@ function close() ...@@ -286,12 +267,12 @@ function close()
<tr> <tr>
<td> <td>
<input type="button" id="PlayOrPause" value=" Play " onClick='doPlayOrPause();'> <input type="button" id="PlayOrPause" style="width:60px" value="Play" onClick='doPlayOrPause();'>
<input type="button" value="Stop" onClick='doStop();'> <input type="button" value="Stop" onClick='doStop();'>
</td> </td>
<td style="text-align:center; width:15%"> <td style="width:100px; text-align:center">
<div id="info">-:--:--/-:--:--</div> <div id="info">-:--:--/-:--:--</div>
<div id="state">Stopped...</div> <div id="state">Idle...</div>
</td> </td>
</tr> </tr>
<tr> <tr>
...@@ -306,108 +287,6 @@ function close() ...@@ -306,108 +287,6 @@ function close()
<script type="text/javascript"> <script type="text/javascript">
<!-- <!--
var rate = 0;
var prevState = 0;
var telxState = false;
var canPause = true;
var canSeek = true;
function setPauseable(val)
{
canPause = val;
}
function setSeekable(val)
{
canSeek = val;
}