MIDI play in background

I wanted to let the user play a MIDI file by clicking with the mouse BUT without involving MediaPlayer !
I was told that BGSOUND should work with any ie plus NS >= 4.0 ...

It works for me with ie 5.0 but nobody else can hear something !

Is it OK for ie ?

How can I mix BGSOUND and EMBED for making it work with both browsers ?



<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="GENERATOR" content="Epsilon 9.0">
<title>PhL's Home Page</title>

<script>function PlayMidi(FileName) {
Midi.src=FileName;
}
</script>

<bgsound id=Midi>

<script> Midi.src='sore17lv.mid'; Midi.loop=1; </script>
</head>

<table border="0">
    <tr>
        <td colspan="3"><font size="4">Click on my compositions to hear them :</font></td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td><img src="look-.gif" width="122" height="38"></a></td>
    </tr>
    <tr>
        <td width="60">&nbsp;</td>
        <td><a href="#f1" onmousedown="PlayMidi('lp.mid')"><font name=f1 size="5" color="#0000FF">Piece</font></a></td>
        <td width="30">&nbsp;</td>
        <td><font color="#808080" size="1" face="Arial Narrow">© 1994</font></td>
        <td width="50">&nbsp;</td>
        <td>&nbsp;</td>
    </tr>
</table>

</body>
</html>
PhLAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

oubelkasCommented:
Just use both embed and bgsound on your page, so something like this :

<embed src="mymidisound.mid" autostart=true hidden=true></embed>

<bgsound src="mymidisound.mid">

Now, in both IE and NS the midi will be heard.

Joseph
0
PhLAuthor Commented:
I want it to be dynamic !
So I need a routine to change the background...

I write one that should work under ie but seems not to work !

The code is above, could you tell why ?

Making it work under NS will be after...

0
PhLAuthor Commented:
So even with ie 5 the HTML code above seems not to work can anyone say why ?

Copying the page and replacing the 2 MIDI files with any other on your HD could let you check...

0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

oubelkasCommented:
Use an array for dynamically changing the background music :

Try,

<script language="JavaScript">
<!--
 //put your own midi files in this array
 midi = new Array('mymidi1.mid', 'mymidi2.mid', 'mymidi3.mid');
 document.write('<embed src="'+ midi[Math.round(Math.random()*(count-1))] +'"  autostart="true" loop="true"><br>');
// -->
</script>

good luck

Joseph
0
PhLAuthor Commented:
By dynamically I meant changing depending of where the user click with his mouse...

Could you be kind enough to try my HTML ?

It was suggested here some time ago and works for me !  I'm just looking to see why it could not work for other ie 5.0 users...  
0
oubelkasCommented:
Mmmm, I tried your code and works fine for me under IE5.0! Of course it doesn't work with NS.

Joseph
0
PhLAuthor Commented:
Nice !
So please ANSWER saying what I have to change to work under both ie and NS

Perhaps add something like :

<embed id=Midi autostart=true hidden=true></embed>

????

I have not NS to try...
Does ie and NS need to have special settings to hear music ?

0
oubelkasCommented:
mmmm, NS is flipping here, I have a page (it's an old one) on http://anime.mypage.org where I use midi too and it works with both IE and NS. But if I copy that code to another html file it won't work anymore in NS. I don't understand this...

<embed> works with both IE and NS now. <bgsound> I think, only works with IE. But like I said I can't test here, NS is driving me nuts...though I will try later on...

Joseph
0
PhLAuthor Commented:
Have your time !

I prefer to have a good solution ...

I have this link but it is too complicated for me without NS !

http://www.aitech.ac.jp/~ckelly/SMFguide/template-26.html
0
oubelkasCommented:
Well, PhL,

I fixed it, you know what the problem was that I couldn't hear any midi sound? Well, I stored it on my local hard disk instead of on the network, so NS couldn't play the midi sound, while IE could (stupid NS!)

But now I tested it for both NS and IE and the solution here works perfectly for both! The code must be changed though, because unlike <bgsound id=Midi> the <embed> tag doesn't recognize "id". But the code I will give is pretty simple. I enhanced the code of the link you gave me in your last comment :

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="GENERATOR" content="Epsilon 9.0">
<title>PhL's Home Page</title>

<script language="javascript"><!--
//this is THE function and as you can see depending on which browser it uses the <embed> tag for NS and <bgsound> for other browsers (IE in most cases)

function PlayMidi(FileName) {
  if (navigator.appName=="Netscape")  
    document.write('<embed src=\"'+FileName+'\" autostart=\"true\" hidden=\"true\">')
  else  
    document.write('<bgsound src=\"'+FileName+'\">')
}
//--></script>

<!-- change these files of course -->
<bgsound src="mymidi.mid">
<embed src="mymidi.mid" autostart="true" hidden="true"></embed>

</head>

<!-- well this is your own code.... -->
<table border="0">
    <tr>
        <td colspan="3"><font size="4">Click on my compositions to hear them :</font></td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td><img src="look-.gif" width="122" height="38"></a></td>
    </tr>
    <tr>
        <td width="60">&nbsp;</td>
        <td><a href="#f1" onmousedown="PlayMidi('mymidi2.mid')"><font name=f1 size="5" color="#0000FF">Piece</font></a></td>
        <td width="30">&nbsp;</td>
        <td><font color="#808080" size="1" face="Arial Narrow">© 1994</font></td>
        <td width="50">&nbsp;</td>
        <td>&nbsp;</td>
    </tr>
</table>

</body>
</html>

Well it works, so this is what you want ;)

Joseph
0
PhLAuthor Commented:
Due to Christmas Eve I have some delay before being able to try...

But I give you an A if it works !
Be patient and best season wishes !
0
PhLAuthor Commented:
I'm afraid there is a problem with ie 5 !

The normal BG starts OK and when you choose a first Midi you get it BUT

1. the animated GIF stops
2. clicking anywhere does not work anymore

In fact the page is replaced by a new one with the lonely line BGSOUND...
although you can think the initial one is till there for ie continues to display it !

So how to make the Java Writing in the current page and not in a new one ?

PS I see no /embed for NS
0
oubelkasCommented:
Best season wished to you too, for a start! ;)

Well,

1) the animated gif stops? Mmmm...it's a shame I haven't got this image, maybe you can send it in by e-mail so I can check it too...

2) you're right...the clicking doesn't work, because of the document.write statement..I shall look for a better alternative.

>>In fact the page is replaced by a new one with the lonely line BGSOUND...

Yep, you're true...gonna check it out...

>>So how to make the Java Writing in the current page and not in a new one ?

Difficult...document.write is a function which normally ADDS some code with your current javascript code, but due of a bug of this function, it throws away all the existing code and replaces it with the html placed inside the document.write().

>>PS I see no /embed for NS

document.write('<embed src=\"'+FileName+'\" autostart=\"true\" hidden=\"true\">')

Joseph
 





0
PhLAuthor Commented:
I think about defining the PlayMidi SCRIPT function from a Java Function and use the Script Function as in the ie only html page...

What do you think ?
0
oubelkasCommented:
Well, PhL, especially for U I figured it out...I tested this again and again, with NS and with IE, with more links. I also tested it with an animated gif of my own, and it kept animating, even after clicking on the links. Well here's the code...I'm a little happy myself to, because there weren't any decent midi-players on the web. All the ones I know use document.write() which is crap!! ;)

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="GENERATOR" content="Epsilon 9.0">
<title>PhL's Home Page</title>

<script language="javascript"><!--
function PlayMidi(FileName) {
  if (document.layers){    
    document.soundlayer.document.open()
    document.soundlayer.document.write('<embed src=\"'+FileName+'\" autostart=\"true\" hidden=\"true\">')
    document.soundlayer.document.close()
  }
  else  {
    soundlayer.innerHTML = '<embed src=\"'+FileName+'\" autostart=\"true\" hidden=\"true\">'
  }
}
//--></script>

<div id="soundlayer" style="position:absolute" width=1 height=1><embed src="bg2.mid" autostart="true" hidden="true"></embed></div>
</head>

<table border="0">
    <tr>
        <td colspan="3"><font size="4">Click on my compositions to hear them :</font></td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td><img src="logo_database_exploits_ani.gif" width="122" height="38"></a></td>
    </tr>
    <tr>
        <td width="60">&nbsp;</td>
        <td><a href="#f1" onmousedown="PlayMidi('bg3.mid');"><font name=f1 size="5" color="#0000FF">Piece</font></a></td>
        <td width="30">&nbsp;</td>
        <td><font color="#808080" size="1" face="Arial Narrow">© 1994</font></td>
        <td width="50">&nbsp;</td>
        <td>&nbsp;</td>
    </tr>
    <tr>
        <td width="60">&nbsp;</td>
        <td><a href="#f1" onmousedown="PlayMidi('bg1.mid');"><font name=f1 size="5" color="#0000FF">Piece 2</font></a></td>
        <td width="30">&nbsp;</td>
        <td><font color="#808080" size="1" face="Arial Narrow">© 1994</font></td>
        <td width="50">&nbsp;</td>
        <td>&nbsp;</td>
    </tr>

</table>

</body>
</html>

Well, good luck with this!! You can reject the first answer and the accept this comment as an answer...or see what you do...phew...another mystery solved :)

Joseph
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
oubelkasCommented:
PS embed also works for IE, so forget bgsound :) and ofcourse change the img src
<td><img src="logo_database_exploits_ani.gif" width="122" height="38"></a></td>
here
0
PhLAuthor Commented:
I try ASAP but remember EMBED should only work with ie 5. perhaps (4.0)

A guy with ie 3 still needs bgsound...
0
PhLAuthor Commented:
It seems OK under ie 5.0 !

2 last questions :

For which browsers is it suppose to work ?

What about not using /embed in JavaScript ?

0
PhLAuthor Commented:
The purpose is to put a text on my page for those who have a non compatible browser in such a way they can upgrade...

Happy new year !
Back the 2.
0
PhLAuthor Commented:
Still not undesrtanding why no \embed is associated with the embed...

However it works
0
oubelkasCommented:
Happy new year to you too PhL! Sorry I didn't respond for a while, but I was of for holidays, so.... ;)

Yup, it works! IE now accepts the embed tag too, so therefore the bgsound isn't needed anymore. IE has done this on purpose for compatibility reasons.

CU!

Joseph

0
PhLAuthor Commented:
The points were :

1. Is <embed> without </embed> OK in the JS ?
2. Which is the first IE to allow embed ?

Happy 19100 too !
0
oubelkasCommented:
Ok,

1. It'll work, but it's better to neatly close the <embed> tag with </embed>, I saw I forgot that, sorry, I'm just human.

2. IE4.0 and up! So this won't be a problem, because more than 90% of the users have IE4.0+

Joseph
0
PhLAuthor Commented:
Thanks !
0
oubelkasCommented:
You're welcome.... ;)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
HTML

From novice to tech pro — start learning today.