Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > How can I play midi and/or audio files?

Reply
Thread Tools

How can I play midi and/or audio files?

 
 
Stephen Kellett
Guest
Posts: n/a
 
      03-24-2006
Hi Folks,

How can I play midi and/or audio files using JavaScript?
I'm hoping there are some calls/APIs I can use that I am unaware of. My
JavaScript book from O'Reilly seems rather lacking in this area.

I'm looking for something like:

playMidiNote(pitch, duration);
playSoundFile(soundFileURL);

but more complex answers are also welcome

Stephen
--
Stephen Kellett
Object Media Limited http://www.objmedia.demon.co.uk/software.html
Computer Consultancy, Software Development
Windows C++, Java, Assembler, Performance Analysis, Troubleshooting
 
Reply With Quote
 
 
 
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      03-24-2006
Stephen Kellett wrote:

> How can I play midi and/or audio files using JavaScript?
> I'm hoping there are some calls/APIs I can use that I am unaware of.
> My JavaScript book from O'Reilly seems rather lacking in this area.
>
> I'm looking for something like:
>
> playMidiNote(pitch, duration);
> playSoundFile(soundFileURL);
>
> but more complex answers are also welcome


<URL:http://groups.google.de/groups?q=midi+OR+sound+OR+multimedia+group%3Acomp. lang.javascript&start=10&scoring=d&hl=de&ie=ISO-8859-15&filter=0>


PointedEars
 
Reply With Quote
 
 
 
 
electrician@electrician.com
Guest
Posts: n/a
 
      03-26-2006
<html>
<head>
<title>Music Selector</title>
</head>
<body text="#FFFFFF" bgcolor="#000000" link="#006400" vlink="#006400"
alink="#FF0000">






<center>

<SELECT id=cancion
onchange=document.all.music.filename=document.all. cancion.value; size=1
name=Music>
<OPTION selected>::::::::::::::::: Choose Your Song Here
:::::::::::::::::</OPTION>
<OPTION
VALUE="http://www.yoursite.com/eltrain/godfathr.mid">Godfather
<OPTION VALUE="http://www.yoursite.com/eltrain/alive.mid ">Alive
<OPTION VALUE="http://www.yoursite.com/eltrain/feel.mid ">Feel
<OPTION VALUE="http://www.yoursite.com/eltrain/mission.mid">mission imp
<OPTION VALUE="http://www.yoursite.com/eltrain/eastern.mid">Eastern
<OPTION VALUE="http://www.yoursite.com/eltrain/thedance.mid ">The Dance
<OPTION VALUE="http://www.yoursite.com/eltrain/theseyes.mid ">These
Eyes
<OPTION VALUE="http://www.yoursite.com/eltrain/blues.mid">Blues
<OPTION VALUE="http://www.yoursite.com/eltrain/italy.mid">Italy
<OPTION VALUE="http://www.yoursite.com/eltrain/europe.mid ">Europe
<OPTION VALUE="http://www.yoursite.com/eltrain/argin.mid ">Argintina
<OPTION VALUE="http://www.yoursite.com/eltrain/poland.mid">Poland
<OPTION VALUE="http://www.yoursite.com/eltrain/india.mid">Optional
<OPTION VALUE="http://www.yoursite.com/eltrain/appal.mid ">Appalachia
<OPTION VALUE="http://www.yoursite.com/eltrain/wondrful.mid ">Wonderful
<OPTION VALUE="http://www.yoursite.com/eltrain/would_i.mid">Would I
<OPTION VALUE="http://www.yoursite.com/eltrain/no-woman.mid">No Woman
<OPTION VALUE="http://www.yoursite.com/eltrain/womnocry.mid ">Woman Cry
<OPTION VALUE="http://www.yoursite.com/eltrain/whatislo.mid ">What
<OPTION VALUE="http://www.yoursite.com/eltrain/stbyme.mid">Stand by
Your Man
<OPTION VALUE="http://www.yoursite.com/eltrain/malovwom.mid ">Man
<OPTION VALUE="http://www.yoursite.com/eltrain/chaingng.mid ">Chain
Gang

<OPTION value=http://www.yoursite.com/yanni/white.mp3>Crosby -
White Christmas</OPTION>
<OPTION value=http://www.yoursite.com/yanni/yanni-1.mid>Yanni -
Yanni-1</OPTION>
<OPTION value=http://www.yoursite.com/yanni/oneman's.mid>Yanni -
One Man's Dream</OPTION>
<OPTION value=http://www.yoursite.com/yanni/whisper3.mid>Yanni -
Whisper3</OPTION>
<OPTION value=http://www.yoursite.com/yanni/yanni2.mp3>Yanni -
Yanni -2 mp3</OPTION>
<OPTION value=http://www.yoursite.com/yanni/rainfall.mid>Yanni -
Rainfall</OPTION>
<OPTION value=http://www.yoursite.com/yanni/whisper.mid>Yanni -
Whisper</OPTION>
<OPTION value=http://www.yoursite.com/yanni/secrtvow.mid>Yanni -
Secret Vow</OPTION>
<OPTION value=http://www.yoursite.com/yanni/quit_man.mid>Yanni -
Quite Man</OPTION>
<OPTION value=http://www.yoursite.com/yanni/reflpass.mid>Yanni -
Reflections</OPTION>
<OPTION value=http://www.yoursite.com/yanni/morning.mid>Yanni -
Morning</OPTION>
<OPTION value=http://www.yoursite.com/yanni/nostal.mid>Yanni -
Nostalgia</OPTION>
<OPTION value=http://www.yoursite.com/yanni/onceupon.mid>Yanni -
Once Upon a time</OPTION>
<OPTION value=http://www.yoursite.com/yanni/swept.mid>Yanni -
Swept Away</OPTION>
<OPTION value=http://www.yoursite.com/yanni/passion.mid>Yanni -
Passion</OPTION>
<OPTION value=http://www.yoursite.com/yanni/aria.mid>Yanni -
Aria</OPTION>

</SELECT><BR />
<OBJECT id=music height="20" width="280"
classid=clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95>
<PARAM NAME="AutoStart" VALUE="-1">
<PARAM NAME="Balance" VALUE="0">
<PARAM NAME="DisplaySize" VALUE="0">
<PARAM NAME="Filename" VALUE="">
<PARAM NAME="Mute" VALUE="0">
<PARAM NAME="SelectionStart" VALUE="-1">
<PARAM NAME="SelectionEnd" VALUE="-1">
<PARAM NAME="ShowControls" VALUE="true">
<PARAM NAME="ShowAudioControls" VALUE="-1">
<PARAM NAME="ShowDisplay" VALUE="0">
<PARAM NAME="ShowPositionControls" VALUE="-1">
<PARAM NAME="Volume" VALUE="0">
<PARAM NAME="AudioStream" VALUE="-1">
<PARAM NAME="AutoSize" VALUE="0">
<PARAM NAME="AnimationAtStart" VALUE="-1">
<PARAM NAME="AllowScan" VALUE="-1">
<PARAM NAME="AllowChangeDisplaySize" VALUE="-1">
<PARAM NAME="AutoRewind" VALUE="1">
<PARAM NAME="BaseURL" VALUE="">
<PARAM NAME="BufferingTime" VALUE="5">
<PARAM NAME="CaptioningID" VALUE="">
<PARAM NAME="ClickToPlay" VALUE="-1">
<PARAM NAME="CursorType" VALUE="0">
<PARAM NAME="CurrentPosition" VALUE="-1">
<PARAM NAME="CurrentMarker" VALUE="0">
<PARAM NAME="DefaultFrame" VALUE="">
<PARAM NAME="DisplayBackColor" VALUE="0">
<PARAM NAME="DisplayForeColor" VALUE="16777215">
<PARAM NAME="DisplayMode" VALUE="0">
<PARAM NAME="Enabled" VALUE="-1">
<PARAM NAME="EnableContextMenu" VALUE="-1">
<PARAM NAME="EnablePositionControls" VALUE="-1">
<PARAM NAME="EnableFullScreenControls" VALUE="0">
<PARAM NAME="EnableTracker" VALUE="-1">
<PARAM NAME="InvokeURLs" VALUE="-1">
<PARAM NAME="Language" VALUE="-1">
<PARAM NAME="PlayCount" VALUE="100">
<PARAM NAME="PreviewMode" VALUE="0">
<PARAM NAME="Rate" VALUE="1">
<PARAM NAME="SAMILang" VALUE="">
<PARAM NAME="SAMIStyle" VALUE="">
<PARAM NAME="SAMIFileName" VALUE="">
<PARAM NAME="SendOpenStateChangeEvents" VALUE="-1">
<PARAM NAME="SendWarningEvents" VALUE="-1">
<PARAM NAME="SendErrorEvents" VALUE="-1">
<PARAM NAME="SendKeyboardEvents" VALUE="0">
<PARAM NAME="SendMouseClickEvents" VALUE="0">
<PARAM NAME="SendMouseMoveEvents" VALUE="0">
<PARAM NAME="SendPlayStateChangeEvents" VALUE="-1">
<PARAM NAME="ShowCaptioning" VALUE="0">
<PARAM NAME="ShowGotoBar" VALUE=0">
<PARAM NAME="ShowStatusBar" VALUE="0">
<PARAM NAME="ShowTracker" VALUE="-1">
<PARAM NAME="TransparentAtStart" VALUE="-1">
<PARAM NAME="VideoBorderWidth" VALUE="0">
<PARAM NAME="VideoBorderColor" VALUE="0">
<PARAM NAME="VideoBorder3D" VALUE="0">
<PARAM NAME="WindowlessVideo" VALUE="0">
</OBJECT>
</center>

</body>
</html>

 
Reply With Quote
 
Randy Webb
Guest
Posts: n/a
 
      03-26-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) said the following on 3/26/2006 1:37 AM:

<snip crappy useless code>

> <SELECT id=cancion
> onchange=document.all.music.filename=document.all. cancion.value; size=1
> name=Music>


What? No GOTO? Aww man, just when I was thinking you were coming around.....

BTW, document.all is IE only. The web is more than that.
And even in IE it doesn't play music on my PC even when I add legitimate
tunes.

Wanna play audio files? Try an M3U file......

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
 
Reply With Quote
 
electrician@electrician.com
Guest
Posts: n/a
 
      03-26-2006
IE forever! Netscape is dead! Just click my public webstat counter at
electrician.com
The windows media player is dynamite. Just look at my illustrious site
http://www.alaskavirtualtour.com Wanna play music, video, slide
shows, virtual movies, applets, and and the whole she bang mixed
together ...take a look at this dynamic site. Try that with your M3U
whatever.
And all the code is wide open ready for stealing.
On GOTO, who needs goto? Just add an if line and a couple brackets.
What, 2000 lines of code separation and six weeks of programming? What
are you some kind of dumbee that can't keep track of those brackets.
GOTO is for the simple minded and we don't want simple minded people
doing this stuff. This way the acamedians can keep a job.

 
Reply With Quote
 
Randy Webb
Guest
Posts: n/a
 
      03-26-2006
(E-Mail Removed) said the following on 3/26/2006 5:46 AM:
> IE forever! Netscape is dead!


Who said anything about Netscrap, err, NetJunk, err, you get the idea.
But, EOLAS loves IE also.....

> Just click my public webstat counter at electrician.com


And exactly ~97.93453% of stats are made up on the spot.

> The windows media player is dynamite. Just look at my illustrious site
> http://www.alaskavirtualtour.com Wanna play music, video, slide
> shows, virtual movies, applets, and and the whole she bang mixed
> together ...take a look at this dynamic site. Try that with your M3U
> whatever.


Do you *really* wanna know what that crappy site looks like in my
browser? I don't think you do.

And, just for you, M3U files are very specifically oriented towards
Microsoft. Maybe if you spent as much time learning what you are talking
about as you do making an idiot of yourself you would know what an M3U
file is.

> And all the code is wide open ready for stealing.


No thanks. Nothing there worth stealing.

> On GOTO, who needs goto?


Not for you, as you wouldn't comprehend the implications but for anybody
else reading this thread:

<URL:
http://groups.google.com/group/comp....2678cf2ffda749
>


Is the thread where *you* were trolling about JS' lack of a GOTO. Does
that mean you finally admit that GOTO is useless?

> Just add an if line and a couple brackets.


You are learning I see.

> What, 2000 lines of code separation and six weeks of programming?


Who said anything about 2,000 lines of code separation and six weeks? Is
that how long it took you to write a simple function to swap images?

> What are you some kind of dumbee that can't keep track of those brackets.
> GOTO is for the simple minded and we don't want simple minded people
> doing this stuff. This way the acamedians can keep a job.


You really are as stupid as you act, you know that?

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
 
Reply With Quote
 
electrician@electrician.com
Guest
Posts: n/a
 
      03-26-2006
Sounds to me like you have a crappy browser that can't read excellent
code. What are you, one of those save the trees, PETA, save Sun and
Netscape self sacrificing geeks? Give it up, move to Windows and IE.
Be a winner. Oh yes, I know about M3U files and they didn't work out
and are not simple enough for my work ethics. Don't forget, I am a
construction electrician with 35 years experience with a Math degree
from 31 years ago. I don't think like a geek, thank god. I do believe
in working with tools and doing hard construction work because it gives
you a concrete background the practical application of time.
Production verses time, get it! You only need to know one thing in
life, kid. And that is know that one thing. My code does the job, and
does it well. You perfectionists from academia waste many hours
learning how to waste your time learning what you don't need to know.
I am proud to say, I have never set foot in a classroom to learn
JavaScript or Perl. Self taught all the way, and proud of it.
On the two thousand lines of code, try the raceway fill calculator.
This program performs a complex engineering calculation. One of the
problems with programmers is that they know how to program but don't
know anything else. They have to be lead by the hand step by step.
But for $100 and hour being dumb is profitable for them, but not
affordable for the rest of us. I had rather hack my way through than
be taken for a ride. Have a nice day, Geek.

 
Reply With Quote
 
Stephen Chalmers
Guest
Posts: n/a
 
      03-27-2006
Stephen Kellett wrote:
> Hi Folks,
>
> How can I play midi and/or audio files using JavaScript?


I have never seen a satisfactory answer to playing sound files
interactively, so here's my solution:

<html>
<body>

<!--
If available, copy the Windows .wav files: blip ding & chimes into the
same folder as this file, or substitute your own.

Files play on mouseover and abort on mouseout
-->

<a href='#'>Blip</a> - <a href='#'>Ding</a> - <a href='#'>Dumb</a> - <a
href='#'>Dumb</a> - <a href='#'>Chime</a>

<script type='text/javascript'>

/*
* Sound File Player (C)2006 Stephen Chalmers
*
* Donations to: http://www.hotspot.freeserve.co.uk/luv2payu/
*
*/

function SCmediaPlay(soundFile)
{
this.soundFile=soundFile;
this.objRef=null;
this.preLoad();
}

SCmediaPlay.prototype.removeObj=function()
{
if(this.objRef!=null)
{
document.body.removeChild(this.objRef);

this.objRef=null;
}
}

SCmediaPlay.prototype.playSound=function()
{

this.removeObj();

this.objRef=document.createElement('embed');

this.objRef.setAttribute("width","0");

this.objRef.setAttribute("height","0");

this.objRef.setAttribute("hidden","true");

this.objRef.setAttribute("src", this.soundFile);

document.body.appendChild(this.objRef);

}

SCmediaPlay.prototype.preLoad=function() /* preloads the associated
plugin & possibly the media file also */
{
document.write("<embed src='"+this.soundFile+"' hidden='true'
autostart='false' width='0' height='0'>");
/* Opera won't recognise autostart using creatElement */
}

if(document.body && document.createElement)
{

/* == CONFIGURATION ==
*
* Populate the object table below with your own filenames and link
indices.
* Preserve the syntax as shown.
*
* ind == the zero-based index of the link that plays a sound.
*
* f == the file to be played by the corresponding link (remember to
add a relative
* path if needed)
*
*/


var SCmediaTable=[ {ind: 0, f: 'blip.wav' },
{ind: 1, f: 'ding.wav' },
{ind: 4, f: 'chimes.wav'}

];


var SCobjTable=[];

for(var i=0; i<SCmediaTable.length; i++)
{
SCobjTable[i]=new SCmediaPlay(SCmediaTable[i].f)
document.links[ SCmediaTable[i].ind ].onmouseover=
new Function("SCobjTable["+i+"].playSound()") ;
document.links[ SCmediaTable[i].ind ].onmouseout=
new Function("SCobjTable["+i+"].removeObj()") ;
}

}
</script>

</body>
</html>

 
Reply With Quote
 
electrician@electrician.com
Guest
Posts: n/a
 
      03-27-2006
What a bunch of crap!

 
Reply With Quote
 
electrician@electrician.com
Guest
Posts: n/a
 
      03-27-2006
<Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices -
http://www.JavascriptToolbox.com/bestpractices/ >

I have looked at your library and don't see a cotton picking thing that
I could have used when I wrote my 17 calculators at electrician.com. I
see from you bio that you started in 1993. I started in 1962
programming a VAC machine in Fortran 2 using punch cards. From there
to Fortran 4, PL/1, Basic, Cbasic, Sbasic, Olivettie programma 101
using the Taylor series to find trig functions, Javascript, and Perl.
And you call me stupid? I would say the best and brightest part of you
ran down your daddies leg when I was doing Fortran (thanks to Lee
Marvin.) Your library may have protability but it does not have
functionality and is not practical for real world applications. You had
better stay in cyberland, kid. And you are a consultant? God help us!

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Portable midi communication with external midi instruments? Asbjørn Bjørnstad Java 0 10-09-2008 03:03 PM
Real Time Midi File Playback - Reading and Writing midi at the sametime Gilly Python 6 05-04-2008 09:16 PM
D/L midi files launches a midi player I want the midi file Vlad Firefox 2 06-10-2005 02:25 AM
Java MIDI output device to MIDI Yoke. Hugo Villeneuve Java 0 07-04-2003 10:31 PM



Advertisments