Java Reference
In-Depth Information
If this is a Microsoft browser, use the readyState property of the <object/> element's Object object
to see if the ActiveX control is loaded, initialized successfully, and now ready for action. If its value is 4,
you know all systems are ready to go, so you set the variable plugInInstalled to true.
Finally, the last if statement in the function checks to see if plugInInstalled is true or false. If
false, the buttons are disabled and an alert box tells the user they need QuickTime in order to play the
audio fi le.
Finishing Up
The last step in creating this audio player is adding functionality to the buttons. As mentioned earlier,
these buttons start and stop the audio fi le's playback. Add the following functions to the script element:
function buttonPlay_onclick() {
document.audioPlayer.Play();
}
function buttonStop_onclick() {
document.audioPlayer.Stop();
}
The QuickTime plug-in control exposes Play() and Stop() methods to play and pause playback
respectively. So the play button should call Play() and the stop button Stop().
You completed the page with this last bit of code. The HTML and JavaScript should now look like this:
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<title>Using JavaScript to Interface with Quicktime</title>
<script type=”text/javascript”>
function buttonPlay_onclick() {
document.audioPlayer.Play();
}
function buttonStop_onclick() {
document.audioPlayer.Stop();
}
function window_onload() {
var plugInInstalled = false;
if (!window.ActiveXObject) {
var pluginsLength = navigator.plugins.length;
for (var i = 0; i < pluginsLength; i++) {
var pluginName = navigator.plugins[i].name.toLowerCase();
if (pluginName.indexOf(“quicktime”) > -1) {
plugInInstalled = true;
break;
}
}
Search WWH ::




Custom Search