Voxware's ToolVox Player plug-in is now LiveConnect compatible. You can control the plug-in via HTML input forms, Java applets and/or JavaScript.
Currently, this capability is only available in the Windows 95 version of the ToolVox Player. Other versions of the ToolVox Player will be "LiveConnected" in the future.
You must have Netscape Navigator 3.0 or later to use the LiveConnect capability of the ToolVox Player. Also, viewers of your Web pages who have a version of Netscape Navigator earlier than 3.0 will get a JavaScript error message, because their browser doesn't support JavaScript. Please keep your audience in mind when using LiveConnect and JavaScript.
This document is an overview of the methods contained in the VoxPlug.class file. The methods can be used with HTML forms, Java applets or JavaScript to operate the ToolVox Player. Note that you must already have the ToolVox Player plugin installed in the Netscape plugin subdirectory (a file called NP32VOX.DLL) and the VoxPlug.class file must also be in the plugins subdirectory.
This document is not a tutorial on Java or JavaScript. It assumes that you have some prior knowledge. If you are not familiar with the basics, we suggest searching the Web for a tutorial or overview document.
IMPORTANT NOTE: Before you can use any of the methods, you must add the ToolVox Player plug-in and specify a VOX file with an EMBED tag on your Web page. In the EMBED tag, add the NAME parameter to define the name for the plug-in object. For our purposes, we'll use the name, ToolVoxPlugIn.
For all of our examples, we will use the VOX file named jfk8.vox, which is a 4 minute, 16 second excerpt from President John F. Kennedy's inaugural address.
<embed src="jfk8.vox" name=ToolVoxPlugIn playmode=user visualmode=background height=2 width=2>
These are the methods that are provided in the VoxPlug.class file. Examples of using each method can be found later in this file. All of these methods operate on the VOX file that was added with the EMBED tag above. Click on a link below for more information about the method:
- play - starts playback
- stop - stops playback
- playAt - starts playback at a specified time
- rewind - sets the playback starting point to the beginning
- setWarp - sets a parameter to speed up or slow down playback
- getWarp - returns the current value of the warp parameter
- setTransposition - sets a parameter to change the pitch
- getTransposition - returns the current value of the transposition parameter
- reset - changes warp, transposition and "play at" values to their defaults
- getDuration - returns the total playback time
- isPlaying - determines whether a file is playing or not
- getCurrentTime - returns the current time of the VOX file that is determines playing
play and stop
The play and stop methods are used to begin and stop playback of a VOX file. No parameters are needed for these methods, and they do not return a value.
Example 1:
Here's a simple form with two buttons to stop and play a VOX file. Click on them to try them out!
The two buttons were created with the following HTML code, which specifies a method (play or stop) to run when the button is clicked. Note that the name of the plug-in object (ToolVoxPlugIn) matches the NAME parameter in the EMBED tag above.
<form> <input type=button value="Play" onClick='document.ToolVoxPlugIn.play()'> <input type=button value="Stop" onClick='document.ToolVoxPlugIn.stop()'> </form>playAt
The playAt method is used to begin playback of a VOX file at a certain time. This method accepts a single floating point value as an input parameter, which is the time (in seconds) to skip from the beginning of the VOX file. The playAt method does not return a value.
Example 2:
The following is an example of a button which will start playback of our VOX file at 33 seconds.
Here's the code that was used to create Example 2:
<form> <input type=button value="Play at 33 Seconds" onClick='document.ToolVoxPlugIn.playAt(33.0)'> <input type=button value="Stop" onClick='document.ToolVoxPlugIn.stop()'> </form>rewind
The rewind method is used set the playback starting point to the beginning of the VOX file. No input parameters are used with this method, and it does not return a value.
Example 3:
Building on our previous examples, the following starts playback of the VOX file at 33 seconds when you click on the "Play at 33 Seconds" button, then the "Rewind" will rewind the file and "Play" button will start playback at the beginning of the file. To test this example, click on the four buttons from left to right.
NOTE: You must click on the buttons in order from left to right. If you click on "Play at 33 Seconds", then click on "Stop" and then "Play", the playback will start again after skipping 33 seconds. The ToolVox Player will remember the "play at" value. (We haven't introduced the reset method yet.)
Here's the code that was used to create Example 3:
<form> <input type=button value="Play at 33 Seconds" onClick='document.ToolVoxPlugIn.playAt(33.0)'> <input type=button value="Rewind" onClick='document.ToolVoxPlugIn.rewind()'> <input type=button value="Play" onClick='document.ToolVoxPlugIn.play()'> <input type=button value="Stop" onClick='document.ToolVoxPlugIn.stop()'> </form>setWarp and getWarp
The setWarp and getWarp methods are used to specify or retrieve a value for the warp parameter, which speeds up or slows down playback. The setWarp method will take a floating point value as input and doesn't return any values. Input values can range from 0.4 to 4.0.
If the input value to setWarp is less than 1, the playback will speed up; if the value is greater than 1, the playback will slow down. HINT: Think of the warp value as a multiplier of the total duration of a file. If a file is 100 seconds long, setting a warp value of .5 will make it 50 seconds long.
The getWarp method does not have any inputs and it will return a floating point value.
In this example, enter a number between 0.4 and 4.0 in the text field, then click on the "Play" button to hear the results. The warp value is set using the setWarp method.
Then click the "Get Warp" button to display the warp value that you entered in a confirmation dialog box. The warp value is retrieved using the getWarp method.
This is the first example that uses JavaScript to validate the input and call the ToolVox Player methods.
Here's the code that was used to create Example 4:
<script language="JavaScript"> // The VerifyInputAndSetWarp function checks if the warp // value entered by the user is within the valid range // (0.4-4.0), and if it is, the function will set the warp // value using the setWarp method. function VerifyInputAndSetWarp(ValueEnteredByUser) { // Call reset to clear other parameters that may have been // set by a previous example. (Example of the reset method // to follow.) document.ToolVoxPlugIn.reset() if (ValueEnteredByUser < 0.4 | ValueEnteredByUser > 4) { alert("Please enter a warp value between 0.4 and 4.0.") } else { var Value = parseFloat(ValueEnteredByUser) document.ToolVoxPlugIn.setWarp(Value) } } // The GetWarpValueAndDisplayIt function will retrieve the // current warp value and display it in a confirmation // dialog box. function GetWarpValueAndDisplayIt() { WarpValue = document.ToolVoxPlugIn.getWarp() confirm("The warp value you entered was " + WarpValue + ".") } </script> <form> Enter a warp value: <input type=text name=warp size=5 onChange="VerifyInputAndSetWarp(form.warp.value)"><br> <input type=button value="Play" onClick='document.ToolVoxPlugIn.play()'> <input type=button value="Stop" onClick='document.ToolVoxPlugIn.stop()'> <br><br> <input type=button value="Get Warp" onClick='GetWarpValueAndDisplayIt()'> </form>setTransposition and getTransposition
The setTransposition and getTransposition methods are used to specify or retrieve a value for the transposition, or pitch, parameter. The value indicates a pitch shift measured in semi-tones. The setTransposition method will take a floating point value as input; this value can range from -12.0 to +12.0. setTransposition does not return any values.The getTransposition method does not have any inputs and it returns a floating point value.
Example 5:
This example works very much like the previous setWarp and getWarp example. Enter a number between -12.0 and +12.0 in the text field, then click on the "Play" button to hear the results. The transposition value is set using the setTransposition method.
Then click the "Get Transposition" button to display the transposition value that you entered in a confirmation dialog box. The transposition value is retrieved using the getTransposition method.
Here's the code that was used to create Example 5:
<script language="JavaScript"> // The VerifyInputAndSetTrans function checks if the transposition // value entered by the user is within the valid range (-12.0 to 12.0), // and if it is, the function will set the transposition value using // the setTransposition method. function VerifyInputAndSetTrans(ValueEnteredByUser) { // Call reset to clear other parameters that may have been set by a // previous example. (Example of the reset method to follow.) document.ToolVoxPlugIn.reset() if (ValueEnteredByUser < -12.0 | ValueEnteredByUser > 12.0) { alert("Please enter a transposition value between -12.0 and +12.0.") } else { var Value = parseFloat(ValueEnteredByUser) document.ToolVoxPlugIn.setTransposition(Value) } } // The GetTransValueAndDisplayIt function will retrieve the current // transposition value and display it in a confirmation dialog box. function GetTransValueAndDisplayIt() { TransValue = document.ToolVoxPlugIn.getTransposition() confirm("The transposition value you entered was " + TransValue + ".") } </script> <form> Enter a transposition value: <input type=text name=transposition size=5 onChange="VerifyInputAndSetTrans(form.transposition.value)"><br> <input type=button value="Play" onClick='document.ToolVoxPlugIn.play()'> <input type=button value="Stop" onClick='document.ToolVoxPlugIn.stop()'> <br><br> <input type=button value="Get Transposition" onClick='GetTransValueAndDisplayIt()'> </form>reset
The reset method is used to change the value of warping, transposition and start time of playback to their default values. Warping will be reset to 1.0; transposition and "play at" time will be set to zero. This method does not have any inputs, and it does not return a value.Example 6:
Click on the "Play" button to hear the VOX file start to play at the 99 second mark with warp set to 0.5. Then click on the "Reset and Play Again" button to reset the "play at" value and warp, and play the VOX file again.
Here's the code that was used to create Example 6:
<script language="JavaScript"> // The SetParametersOrResetThenPlay function will set the // play at value to 99 seconds and warp to 0.5, then play // OR // reset and playback file from beginning function SetParametersOrResetThenPlay(reset) { // Call reset to clear other parameters that may have been // set by a previous example. document.ToolVoxPlugIn.reset() if (!reset) { document.ToolVoxPlugIn.stop() document.ToolVoxPlugIn.playAt(99) document.ToolVoxPlugIn.setWarp(0.5) } else { document.ToolVoxPlugIn.stop() document.ToolVoxPlugIn.reset() } document.ToolVoxPlugIn.play() } </script> <form> <input type=button value="Play" onClick='SetParametersOrResetThenPlay(0)'> <input type=button value="Reset and Play Again" onClick='SetParametersOrResetThenPlay(1)'> <input type=button value="Stop" onClick='document.ToolVoxPlugIn.stop()'> </form>getDuration
The getDuration method is used to return the total playback time of a VOX file. This method does not have any inputs, and will return a floating point value.Example 7:
Click on the "Get Duration" button to display a confirmation dialog with the total playback time of the VOX file.
Here's the code that was used to create Example 7:
<script language="JavaScript"> // The GetDurationOfFile function uses the getDuration // method to retrieve the total playback time and // display it in a confirmation dialog. function GetDurationOfFile() { Duration = document.ToolVoxPlugIn.getDuration() confirm("The total playback time of the file is: " + Duration + " seconds.") } </script> <form> <input type=button value="Get Duration" onClick=GetDurationOfFile()> </form>isPlaying
The isPlaying method is used to determine whether or not the VOX file is currently playing. This method does not have any inputs, and will return a Boolean value (TRUE or 1), if the VOX file is playing. FALSE or 0 is returned if the VOX file is not playing.Example 8:
In this example, click on the "Play" or "Stop" button, then click on the "Check if File's Playing" button. A confirmation box will be displayed with the current status.
Here's the code that was used to create Example 8:
<script language="JavaScript"> // The IsFilePlaying function uses the isPlaying method // to determine if the VOX file is playing. The file's // playback status will be displayed in a confirmation // dialog. function IsFilePlaying() { Result = document.ToolVoxPlugIn.isPlaying() if (Result) confirm("The file is playing.") else confirm("The file is NOT playing.") } </script> <form> <input type=button value="Play" onClick='document.ToolVoxPlugIn.play()'> <input type=button value="Stop" onClick='document.ToolVoxPlugIn.stop()'> <input type=button value="Check if File's Playing" onClick=IsFilePlaying()> </form>getCurrentTime
The getCurrentTime method is used to return the current time of the playing VOX file in seconds. This method does not have any inputs, and will return a floating point value.Example 9:
In this example, click on the "Play" button to start the VOX file, then click on "Get Time". The current time in seconds of the playing VOX file will be displayed in the text field. You can click on the "Get Time" button many times and see the value in the text field increase. Try it!
Here's the code that was used to create Example 9:
<script language="JavaScript"> function Play() { document.ToolVoxPlugIn.play() } // The SetTimeInTextField function uses the getCurrentTime // method to return the time of the VOX file that is playing (in // seconds) and places the value in the text field named textform. function SetTimeInTextField(form) { Value = document.ToolVoxPlugIn.getCurrentTime() Value = parseFloat(Value) form.textform.value = Value } </script> <form> <input type=button value="Play" onClick=Play()> <input type=button value="Get Time" onClick=SetTimeInTextField(form)> <input type=text name=textform value=""> <input type=button value="Stop" onClick="document.ToolVoxPlugIn.stop()"> </form>