
August 3rd, 2003
09:04 PM
Play a MIDI file when you click on an icon
Im building a ring tone site and Im kinda stuck at this one place
I want it so that the user can preview the ringtone before they download it, and to do that I want them to clcik on a speaker icon.However, I dont want anythign ti pop up and the ringtone should play.
To get an idea of what im talkin bout, go to www.mrtones.com and check it out. When you click on the icon, the ringtone plays
Whats the code for it? I cant seem to figure it out :confused:
thanks
___________________


August 3rd, 2003
09:08 PM
No problem - I know exactly how this is done. I'll write the script right now...
___________________


August 3rd, 2003
09:18 PM
yay
lol..thx..ur a life saver...mmmm...life saver
lol
___________________


August 3rd, 2003
09:31 PM

Alright, I'm done. I tried to make it cross-browser compatiable as well -- If their browser doesn't support it, it will tell the user. You just call the function like this in your links:
<a href = "#" onclcik = "playMidi('filename.mid');">Play filename.mid!</a>
Where "filename.mid" is the name of the MIDI file.
I uploaded a demo which you can find here:
http://home.comcast.net/~fredv4/tf/midi.html
I have some NIRVANA MIDIs which use the script I wrote to play them.
Here's the function:
<script type = "text/javascript">
document.writeln("<div id = 'player' style = 'visibility: hidden; top: 0px; left: 0px; position: absolute;'><\/div>");
function playMidi(f)
{
if(document.getElementById)
{
document.getElementById("player").innerHTML = "<embed src = '" + f + "' autostart = 'true' height = '0' width = '0' hidden = 'true'><\/embed>";
}
else if(document.all)
{
document.all.player.innerHTML = "<embed src = '" + f + "' autostart = 'true' height = '0' width = '0' hidden = 'true'><\/embed>";
}
else if(document.layers)
{
with(document.layers["player"].document)
{
open();
write("<embed src = '" + f + "' autostart = 'true' height = '0' width = '0' hidden = 'true'><\/embed>");
close();
}
}
else
{
window.alert("Your browser does not support this function.\n");
return false;
}
return;
}
</script>
Well - Hope that helps you out! 
___________________

Last edited by fredmv, August 3rd, 2003 09:44 PM (Edited 1 times)

August 3rd, 2003
09:49 PM
hmm..your preview doesnt work for me. I mean it dosnt play the files when I click on them.
And i tried it on my site too, same thing, it appears but once u click on it, nothing happens
If it works for you, I dunno why it doesnt work for me 
___________________


August 3rd, 2003
09:52 PM
What browser are you running? If you're running Netscape/Mozilla it's probably because you don't have the plug-in properly configured.
And you might need to wait a little for the MIDI to download...
___________________


August 3rd, 2003
09:55 PM
im using IE 6....with windows XP
i kno my speakers are on..lol..and i waited for a while.....still not playin...
shyt..and i gotta go take my mom to wal mart now...i'll be back later...see if you can figure out wha the problem is
___________________


August 3rd, 2003
09:56 PM
Ah, stupid *** IE6... I'll test it out and find out what's wrong.
*** EDIT ***
I think I may have fixed it:
http://home.comcast.net/~fredv4/tf/midi.html
___________________

Last edited by fredmv, August 3rd, 2003 10:13 PM (Edited 1 times)

August 3rd, 2003
11:02 PM
GOOD JOB
lol..thx man...your demo works..now to plug it into my thing and hope for the same
___________________


August 3rd, 2003
11:29 PM
Alright, great! Happy that worked out...
Seems like IE6 wants you to use <bgsound> rather than <embed> -- Kind of weird.
Also just to let you know, the script at MrTones.com sucks, it will only work with IE since they're using document.all to access objects in the document, the script I wrote for you should work in IE, Netscape, Mozilla, etc.
___________________
