/    Sign up×
Community /Pin to ProfileBookmark

Getting Netscape 7.0 and Opera 7.54 to change the MP3 being played

I have created a website to showcase the music I have created with a couple of friends.
It’s at [url]www.mark3music.com[/url]

At [url]http://www.mark3music.com/2004/mark3_instrumental.shtml[/url]
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.

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@Warren86Nov 26.2004 — If you visit Microsoft MSDN and search for embedding Windows Media Player, you will see that the Object ID for the player I provided to you, and which you already had, is for Windows Media Player version 6.4.

The Microsoft technical notes indicate that if you want to support Netscape users, embed version 6.4.

You are attempting to solve a problem that does not exist. You are adding code to your page that isn't needed.

Why not just try the code I previously provided to you, using Netscape?
Copy linkTweet thisAlerts:
@Warren86Nov 26.2004 — This was copied directly from the Microsoft site.

<HTML>

<HEAD>

<TITLE>Document Title</TITLE>

</HEAD>

<BODY>

<script language="JavaScript">

<!--

if ( navigator.appName == "Netscape" )

{

//-- This next line ensures that any plug-ins just installed are updated in the browser

//-- without quitting the browser.

navigator.plug-ins.refresh();

// We don't need the APPLET within IE

// ***Please note that if you do not need to script events, you can safely remove the next two lines

document.write("x3C" + "applet MAYSCRIPT Code=NPDS.npDSEvtObsProxy.class")

document.writeln(" width=5 height=5 name=appObsx3E x3C/appletx3E")

}

//-->

</script>

<!-- Set ShowControls, ShowDisplay, ShowStatusBar to value 0 to not display the corresponding thing under the video window -->

<OBJECT ID="MediaPlayer" WIDTH=320 HEIGHT=240 classid="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95"

codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,7,1112"

standby="Loading Microsoft Windows Media Player components..."

type="application/x-oleobject">

<PARAM NAME="FileName" VALUE="Station1.asx">

<PARAM NAME="ShowControls" VALUE="1">

<PARAM NAME="ShowDisplay" VALUE="1">

<PARAM NAME="ShowStatusBar" VALUE="1">

<PARAM NAME="AutoSize" VALUE="1">

<Embed type="application/x-mplayer2"

pluginspage="http://www.microsoft.com/windows/windowsmedia/download/"

filename="Station1.asx"

src="Station1.asx"

Name=MediaPlayer

ShowControls=1

ShowDisplay=1

ShowStatusBar=1

width=320

height=240>

</embed>

</OBJECT>

</BODY>

</HTML>
Copy linkTweet thisAlerts:
@Mark_M2authorNov 28.2004 — To Warren,

Thanks again for taking the time to reply and sorry for the delay in replying.

I studied your code and the code at Microsoft MSDN and implemented the relevant bits.

When you come to my page http://www.mark3music.com/2004/mark3_instrumental.shtml

I don't want any music to be playing until the user has selected a track. Once a track is selected my function does the following:

var PlayerObj = document.getElementById('MediaPlayer');

PlayerObj.filename = fName;

PlayerObj.Play();

That works fine in IE, but does not work in Opera or Netscape.

Looking at the relevant JavaScript consoles reveals that neither browser recognises the play function as written. In the end I have written code that checks for the browser and runs code that works for that browser.

For Opera that is:

document.MediaPlayer.SetAutoStart(true);

document.MediaPlayer.SetFileName(fName);

For Netscape it involves:

document.getElementById('ObjectEmbed').innerHTML = objectString;

where ObjectEmbed is the DIV surrounding the Object and Embed elements

and objectString is all the relevant HTML with variables to adjust the MP3 filename.

Best regards,

Mark M.
×

Success!

Help @Mark_M2 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...