PDA

View Full Version : Windows Media Player Plug In and Javascript


andyjr
02-06-2003, 01:09 PM
I have written a javascript file for a html page that when clicked parameters are passed that create a new window and load the Windows media player 6.4 plug in to play the MP3 file I have passed it. However using IE 5.5 the file is unloaded and the plug in greyed out with an error message saying Syntax error. Using Netscape seven the plug in works and the MP3 is played. However if I view the source under IE of the created window and save it as a new html file and load it seperately it works perfectly. Is this a bug possibly with Windows Media player or IE.

Randall
02-06-2003, 06:31 PM
Without knowing what code you're using in your script, it's gonna be hard for anyone to give you useful advice. "Syntax error" could mean a lot of things. ;)

Randall

andyjr
02-06-2003, 06:46 PM
Here is the javascript code

var ggWinSound;
var fontface = "Tahoma";
var fontsize = 2;

soundbit.general = ["Cavatina", "Meditation", "1st Arabesque", "I Dreamed a Dream"];

soundbit.wedding = ["Trumpet Voluntary", "Arrival of the Queen of Sheba", "Flower Duet", "Spring", "Canon", "Someone To Watch Over Me"];

soundbit.type = ["General Repertoire", "Music for Weddings"];

function soundbit(song, p_WinSound, song_type, song_file) {

this.songfile = song_file;
this.gWinSound = ggWinSound;
if (p_WinSound == null)
this.gWinSound = ggWinSound;
else
this.gWinSound = p_WinSound;
if (song_type == 0) {
this.soundbname = soundbit.get_general(song);
} else {
this.soundbname = soundbit.get_wedding(song);
}
this.songtype = soundbit.get_type(song_type);
this.gBGColor = "white";
this.gFGColor = "black";
this.gTextColor = "black";
this.gHeaderColor = "black";
}

soundbit.get_type = soundb_get_type;
soundbit.get_general = soundb_get_general;
soundbit.get_wedding = soundb_get_wedding;
new soundbit();


function soundb_get_type(monthNo) {
return soundbit.type[monthNo];
}

function soundb_get_general(monthNo) {
return soundbit.general[monthNo];
}

function soundb_get_wedding(monthNo) {
return soundbit.wedding[monthNo];
}

soundbit.prototype.show = function() {

var vCode = "";

this.gWinSound.document.open();

// Setup the page...
this.wwrite("<html>");
this.wwrite("<head><title>Sound Bites</title>");
this.wwrite("</head>");

this.wwrite("<body bgcolor=\"#FFFFFF\" " +
"link=\"" + this.gLinkColor + "\" " +
"vlink=\"" + this.gLinkColor + "\" " +
"alink=\"" + this.gLinkColor + "\" " +
"text=\"" + this.gTextColor + "\">");
this.wwrite("<P align=\"center\"> ");
this.wwrite("<OBJECT ID=\"MediaPlayer\" WIDTH=200 HEIGHT=42 ");
this.wwrite("CLASSID=\"CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95\" ");
this.wwrite("STANDBY=\"Loading Windows Media Player components...\" ");
this.wwrite(" TYPE=\"application/x-oleobject\">");
this.wwrite("<PARAM NAME=\"Autostart\" VALUE=\"False\" >");
this.wwrite("<PARAM NAME=\"Filename\" VALUE=\"sounds/" + this.songfile + "\">");
this.wwrite("<EMBED TYPE=\"application/x-mplayer2\" src=\"sounds/" + this.songfile + "\" NAME=\"MediaPlayer\" autostart=0 WIDTH=200 HEIGHT=42></EMBED>");
this.wwrite("</OBJECT>");
this.wwrite("</p>");




this.wwrite("<p align=\"center\"><font face=\"Tahoma\" size=\"4\">" + this.songtype + "[nbsp]</font>");
this.wwrite("<p align=\"center\"><font face=\"Tahoma\" size=\"3\">" + this.soundbname + "</font></p>");

this.wwrite("</body></html>");
this.gWinSound.document.close();

}

soundbit.prototype.wwrite = function(wtext) {
this.gWinSound.document.writeln(wtext);
}

soundbit.prototype.wwriteA = function(wtext) {
this.gWinSound.document.write(wtext);
}


function Build(song, song_type, song_file) {
var p_WinSound = ggWinSound;
gSound = new soundbit(song, p_WinSound, song_type, song_file);

// Customize Window here.
gSound.gBGColor="white";
gSound.gLinkColor="black";
gSound.gTextColor="black";
gSound.gHeaderColor="darkgreen";
gSound.show();

}


function show_song() {
/*
Song
*/
song = arguments[0];
song_type = arguments[1];
song_file = arguments[2];

vWinSound = window.open("", "Soundbites",
"width=250,height=250,status=no,resizable=no,top=200,left=200");
vWinSound.opener = self;
ggWinSound = vWinSound;
if (!vWinSound.opener) vWinSound.opener = self;
Build(song, song_type, song_file);
if (!vWinSound.opener) vWinSound.opener = self;

}

Randall
02-06-2003, 08:47 PM
I was hoping I could test your code here, but I'm probably doing something wrong.

Do you get a little "!" icon in the bottom left corner of the IE window when you run it? Clicking on that would bring up an error dialog, and when you click on Details (?) it should give you a line number where the error occured. That would help narrow it down.

Unless someone else can see the problem in the code?

Randall

Lot of unanswered questions here today. Where have all our experts gone?

andyjr
02-06-2003, 10:50 PM
No I get no icon. The window appears as it should but windows Media player does not load the file. f I right click on the WIndows media player plugin and goto error details it says syntax error but won't give any other details. However if I copy the generated HTML into another file and load it it works fine. I am wondering if it is a bug with Windows Media Player but haven't seen anything on the Microsoft web site

Randall
02-07-2003, 12:32 AM
OK. Having concluded that the filename manipulation functions were distracting me from the meat of the script, I've stripped it down slightly. ;)

The following code works for me using IE 6.0 and Windows Media Player 6.4.09.1124. Make sure it works on your system, and then we can work backwards from there.
<html><body>

<script language="JavaScript1.2">

this.songfile = "insert.name.of.song.file";

document.write("<body bgcolor=\"#FFFFFF\" >");
document.write("<P align=\"center\"> ");
document.write("<OBJECT ID=\"MediaPlayer\" WIDTH=200 HEIGHT=42 ");
document.write("CLASSID=\"CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95\" ");
document.write("STANDBY=\"Loading Windows Media Player components...\" ");
document.write("TYPE=\"application/x-oleobject\">");
document.write("<PARAM NAME=\"Autostart\" VALUE=\"False\" >");
document.write("<PARAM NAME=\"Filename\" VALUE=\"sounds/" + this.songfile + "\">");
document.write("<EMBED TYPE=\"application/x-mplayer2\" src=\"sounds/" +
this.songfile + "\" NAME=\"MediaPlayer\" autostart=0 WIDTH=200 HEIGHT=42></EMBED>");
document.write("</OBJECT>");
document.write("</p>");

</script>

</body></html> Randall

andyjr
02-07-2003, 11:09 AM
I did as you suggested but it hasn't made any difference. I am wondering whether when creating an HTML page from within another as we are doing here and incorporating the WIndows Media player plug in that this does not work properly when you try to load in a file. I have tried it on a computer with Windows Media Player 9 and it works fine.

Randall
02-07-2003, 04:22 PM
My stripped-down version didn't work either? It's not creating a second HTML file in this case -- just inserting code into an existing one. I kept it as simple as possible, hoping that would give you a working example to start from.

Before you give up, try this. It's the same HTML, but all of the Javascript code has been removed.
<html><body>

<P align="center">
<OBJECT ID="MediaPlayer" WIDTH=200 HEIGHT=42
CLASSID="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95"
STANDBY="Loading Windows Media Player components..."
TYPE="application/x-oleobject">
<PARAM NAME="Autostart" VALUE="False">
<PARAM NAME="Filename" VALUE="sounds/insert.filename.here">
<EMBED TYPE="application/x-mplayer2" src="insert.filename.here"
NAME="MediaPlayer" autostart=0 WIDTH=200 HEIGHT=42>
</EMBED>
</OBJECT>
</p>

</body></html> Randall

andyjr
02-07-2003, 06:58 PM
To do this I need to save a separate Html file and yes in doing so this works fine. It is only a problem when I use javascript create a window with the media server plugin (V6.4) in it which is why I am coming to the opinion there is a bug somewhere as is works with wmp v9 (unfortunately not everyone has v9). I am now contemplating creating and saving a file with the above in and jsuing javascript to pass it parameters rather than creating the file from scratch at run time.

Randall
02-07-2003, 09:13 PM
That's exactly what I was going to suggest. It's hard to know if this is a problem with certain versions of Media Player, or a an IE/Javascript bug. Better to keep it as simple as possible.

Randall

Norzilla
08-09-2003, 08:04 PM
Message to Randall and andyjr concerning the embedded Windows Media Player.

I have been trying to do exactly the same thing: window A opens window B, then does document.writes into windows B, setting up the embedded WMP. IT DOES NOT WORK.

Works fine from a standalone page: if the code is embedded in window A, then window A correctly hosts WMP and everything works correctly.

I have not been able to get window B to play anything. I can see the WMP. It is sort of greyed out. It does nothing. Frustrating.

Randall, have you got a clue about this? I think maybe it only works with WMP v9. I don't think earlier versions support this. Why? Only Microsoft knows.

Do you know anything more about this?
This should be standard fare for web dev. Kind of inexcusable that it doesn't work.

Anybody know anything about embedding an applet which hooks the WMP? I have been digging around google, and there are many hits, but no one seems to really know anything about the 'secondary window' problem (meaning, getting it to work in a spawned window).

Somebody must know something....
Norzilla

Randall
08-09-2003, 11:11 PM
Well, I'm no expert in this area. Between the two of us, we concluded that older WMP versions won't embed in a second window using document.write() -- but you seem to have figured that out already. ;)

Can you use the workaround andyjr eventually settled on? Essentially he created a separate HTML file for Window B with the embedding code already in place. Then he launched it from Window A, passing his parameters in the process.

Randall

musicarr
09-05-2003, 07:15 PM
Hi,

I, too, am having the same problem. I'm glad I saw this post. I makes me not quite so frustrated. Now, concerning what you suggested, Randall, I make a separate HTML page with the embedded media player code in it, then pass varibles to the newly loaded page. How would I pass the variables to the new page?

Thanks,

Mark

Randall
09-05-2003, 08:02 PM
Well, I'm not sure about that myself -- I notice now that andyjr didn't say how he intended to do it, and I'm still kinda ignorant about javascript.

I suppose the first page could store the variable as a cookie, which the second page would read. A better option might be to pass it as part of the URL, as in <a href="player.html?file=blah.mp3">. I looked around a bit and found this function: <script Language="JavaScript">
//
// QueryString
//

function QueryString(key)
{
var value = null;
for (var i=0;i<QueryString.keys.length;i++)
{
if (QueryString.keys[i]==key)
{
value = QueryString.values[i];
break;
}
}
return value;
}

QueryString.keys = new Array();
QueryString.values = new Array();

function QueryString_Parse()
{
var query = window.location.search.substring(1);
var pairs = query.split("&");

for (var i=0;i<pairs.length;i++)
{
var pos = pairs[i].indexOf('=');
if (pos >= 0)
{
var argname = pairs[i].substring(0,pos);
var value = pairs[i].substring(pos+1);
QueryString.keys[QueryString.keys.length] = argname;
QueryString.values[QueryString.values.length] = value;
}
}

}

QueryString_Parse();
</script> QueryString("file") should return "blah.mp3" in my example.

Let us know if it works!

Randall

musicarr
09-05-2003, 10:46 PM
Hi Randall,

Thanks for the reply. I'll check it out this weekend and let you know what I come up with.

Mark