You can edit the batch file if you wish. The important line
is:
Note: Windows Media Player will play .WMA files, but
Quicktime Player (which Firefox, Safari and Opera uses),
will NOT play .WMA files.
Load A Song
Then we use the following function to create the player
and load the song:
function load(media)
{
var player = document.getElementById('player');
if (detect_browser() == "MSIE" ||
detect_browser() == "Netscape")
{
player.innerHTML = '<object id="sound"'
+ 'classid="clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6"'
+ 'codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701"'
+ 'standby="Loading Microsoft® Windows® Media Player components..."'
+ 'type="application/x-oleobject" width="160" height="144">'
+ '<param name="url" value="'+media+'">'
+ '<param name="volume" value="100">'
+ '<embed id="sound" type="application/x-mplayer2" src="'+media+'"'
+ 'classid="clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6"'
+ 'pluginspage="http://www.microsoft.com/Windows/MediaPlayer/"'
+ 'type="application/x-mplayer2"'
+ 'url="'+media+'"'
+ 'voume="100"'
+ 'width="160" height="144">'
+ '<\/embed>'
+ '<\/object>';
}
else // if Safari or Firefox, then load Quicktime controls
{
player.innerHTML = '<OBJECT '
+ 'CLASSID="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" '
+ 'WIDTH="160"HEIGHT="144" ID="sound"'
+ 'style="position:absolute;left:-1000;top:-1000"'
+ 'CODEBASE="http://www.apple.com/qtactivex/qtplugin.cab">'
+ '<PARAM name="SRC" VALUE="'+media+'">'
+ '<PARAM name="AUTOPLAY" VALUE="true">'
+ '<PARAM name="CONTROLLER" VALUE="false">'
+ '<PARAM name="VOLUME" VALUE="100">'
+ '<PARAM name="ENABLEJAVASCRIPT" VALUE="true">'
+ '<PARAM name="TYPE" VALUE="audio/wav">'
+ '<embed classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B"'
+ 'name="sound"'
+ 'id="sound"'
+ 'src="'+media+'"'
+ 'pluginspage="http://www.apple.com/quicktime/download/"'
+ 'volume="100"'
+ 'enablejavascript="true" '
+ 'type="audio/wav" '
+ 'height="16" '
+ 'width="200"'
+ 'style="position:absolute;left:-1000;top:-1000"'
+ 'autostart="true"'
+ '> </embed>'
+ '</OBJECT>';
}
} // end function load(media)
Object tag
The object tag has the following properties to specify
which player to use: CLASSID, CODEBASE, STANDBY and
TYPE.
Embed tag
The embed tag has the following properties to specify
which player to use: CLASSID, TYPE and PLUGINSPAGE.
CLASSID="clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6" specifies
windows media player 7 or later.
CLASSID="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" specifies
Quicktime.
pluginspage="http://www.microsoft.com/Windows/MediaPlayer/"
specifies where they can download Windows Media Player if they
do not have it.
pluginspage="http://www.apple.com/quicktime/download/"
specifies where they can download Quicktime if they do not
have it.
type="application/x-mplayer2" tells the browser we are loading
windows media player activex controls.
type="audio/wav" tells the browser we are loading wav or mp3
files with quicktime.
To support Safari and older versions of browsers that don't
support the control of media players in the browser using
Javascript we have included the commands to autostart the song.
The function load(media) is called when the user presses the
Play button.
Javascript Controls
Quicktime
In order to control quicktime with Javascript, the following
must be included in the embed statement:
enablejavascript="true"
Also notice that we have included both ID="sound"
and NAME="sound" for the Quicktime player embed
statement. If we only had the ID="sound" identifier then
we would still be able to control the Quicktime Player by using
document.embeds['sound']. We could use functions such as
the following to control the music:
document.embeds['sound'].Stop(); // Pause
document.embeds['sound'].Play(); // Play
document.embeds['sound'].GetVolume(); // Get Volume Level
document.embeds['sound'].SetVolume(x); // Set Volume from 0 to 256(loudest)
document.embeds['sound'].GetTime(); // Get Current Time in song
document.embeds['sound'].GetDuration(); // Get Duration of song
document.embeds['sound'].GetTimeScale(); // Get TimeScale
(NOTE: The time scale of Quicktime songs is not always in seconds.
To convert the current time and current duration of the song to
minutes:seconds, here is the formula:
time = document.embeds['sound'].GetTime();
duration = document.embeds['sound'].GetDuration();
scale = document.embeds['sound'].GetTimeScale();
time = Math.floor(time*(1/scale)); // convert to seconds
duration = Math.floor(duration*(1/scale)); // converts to seconds
// convert seconds into mm:ss
mins = Math.floor(time / 60);
secs = time - (mins * 60);
time = mins + ':' + secs;
mins = Math.floor(duration / 60);
secs = duration - (mins * 60);
duration = mins + ':' + secs;
Since we also include NAME="sound" in the Quicktime
embed statement, we are also able to control the player with
document.sound. We could use functions such as the following
to control the music:
document.sound.Stop(); // Pause
document.sound.Play(); // Play
document.sound.GetVolume(); // Get Volume Level
document.sound.SetVolume(x); // Set Volume from 0 to 256(loudest)
For a complete list of Quicktime Javascript Controls
go to:
MP3 ID3 Tag info
Quicktime includes a way to get the artist name and song title
from the MP3 ID3 tag using javascript:
song_title = document.sound.GetUserData('©nam');
song_artist = document.sound.GetUserData('©ART');
At first I thought these functions did not work because they
kept returning null. I finally realized that they did
work but I was calling them too quickly after loading the song.
Quicktime has to load most of the mp3 music file before it can
tell you the ID3 tag information. So now the display_info()
function in sound.js calls itself again if the above functions
return null:
song_title = document.sound.GetUserData('©nam');
song_artist = document.sound.GetUserData('©ART');
/* Quicktime has a problem of not being able to load
the song name and artist until most of the song is
loaded, so if song_title == null we need to call this
function again in a few milliseconds */
if (song_title == null)
{
setTimeout('display_info();', 250);
return;
}