I have created a website to showcase the music I have created with a couple of friends.
It’s at [url]www.mark3music.com
At [url]http://www.mark3music.com/2004/mark3_instrumental.shtml
there is a page that allows you to pick an instrumental track to listen to.
With Warren86’s help I got it to work in IE using the Object element.
Unfortunately it does not work for Netscape or Opera when using the Embed element.
The function playSong is called when you click on the name of a track
<li ><a href=”#” onclick=”playSong(‘i_dreams_of_sand.mp3’);”>Dreams of Sand</a></li>
I employed the usual Embed element nested inside the Object element.
<object id=”Player” width=”270″ height=”45″ classid=”CLSID:22D6f312-B0F6-11D0-94AB-0080C74C7E95″ type=”applicaton/x-oleobject”>
<embed type=”application/x-mplayer2″ src=”../mp3_lo/i_pgm.mp3″ name=”EmbedPlayer” id=”EmbedPlayer” autostart=”false” height=”45″ width=”270″ mastersound>
</embed>
</object>
To cater for Netscape and Opera browsers I wrote the following code in the function playSong:
var EmbedPlayerObj = document.getElementById(‘EmbedPlayer’);
if (EmbedPlayerObj) { // If the browser saw the embed element
playEmbedSong(fName); // call this function for browsers like Netscape and Opera that see the Embed player
}
I did it this way in case future versions of these browsers do recognise the Object element.
Finally the function to control the Embed element:
function playEmbedSong(embed_fName) {
var EmbedPlayerObj = document.getElementById(‘EmbedPlayer’);
document.EmbedPlayer.stop()
EmbedPlayerObj.src = embed_fName;
var playerStatus = document.EmbedPlayer.GetPlayState(); // GetPlayState(); works for Opera. 0=stop, 1=pause, 2=play
document.EmbedPlayer.play()
}
From Netscape’s JavaScript console:
Error: document.EmbedPlayer.stop is not a function
document.EmbedPlayer.play() is also deemed not to be a function.
I’ve tried it with and without the semi-colon.
I’ve also tried EmbedPlayerObj.play()
What does work:
EmbedPlayerObj.src = embed_fName;
as revealed by alert(EmbedPlayerObj.src); it shows the filename of the MP3 file you have chosen.
var playerStatus = document.EmbedPlayer.GetPlayState();
This works in Opera only.
Is it possible to dynamically change the current MP3 file being played within the Netscape and Opera browsers?
Any help or hints will be much appreciated.
Mark M.