473,748 Members | 2,361 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How can I play midi and/or audio files?

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(pi tch, duration);
playSoundFile(s oundFileURL);

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
Mar 24 '06 #1
20 3249
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(pi tch, duration);
playSoundFile(s oundFileURL);

but more complex answers are also welcome :-)


<URL:http://groups.google.d e/groups?q=midi+O R+sound+OR+mult imedia+group%3A comp.lang.javas cript&start=10& scoring=d&hl=de &ie=ISO-8859-15&filter=0>
PointedEars
Mar 24 '06 #2
<html>
<head>
<title>Music Selector</title>
</head>
<body text="#FFFFFF" bgcolor="#00000 0" link="#006400" vlink="#006400"
alink="#FF0000" >


<center>

<SELECT id=cancion
onchange=docume nt.all.music.fi lename=document .all.cancion.va lue; size=1
name=Music>
<OPTION selected>:::::: ::::::::::: Choose Your Song Here
::::::::::::::: ::</OPTION>
<OPTION
VALUE="http://www.yoursite.co m/eltrain/godfathr.mid">G odfather
<OPTION VALUE="http://www.yoursite.co m/eltrain/alive.mid ">Alive
<OPTION VALUE="http://www.yoursite.co m/eltrain/feel.mid ">Feel
<OPTION VALUE="http://www.yoursite.co m/eltrain/mission.mid">mi ssion imp
<OPTION VALUE="http://www.yoursite.co m/eltrain/eastern.mid">Ea stern
<OPTION VALUE="http://www.yoursite.co m/eltrain/thedance.mid ">The Dance
<OPTION VALUE="http://www.yoursite.co m/eltrain/theseyes.mid ">These
Eyes
<OPTION VALUE="http://www.yoursite.co m/eltrain/blues.mid">Blue s
<OPTION VALUE="http://www.yoursite.co m/eltrain/italy.mid">Ital y
<OPTION VALUE="http://www.yoursite.co m/eltrain/europe.mid ">Europe
<OPTION VALUE="http://www.yoursite.co m/eltrain/argin.mid ">Argintina
<OPTION VALUE="http://www.yoursite.co m/eltrain/poland.mid">Pol and
<OPTION VALUE="http://www.yoursite.co m/eltrain/india.mid">Opti onal
<OPTION VALUE="http://www.yoursite.co m/eltrain/appal.mid ">Appalachi a
<OPTION VALUE="http://www.yoursite.co m/eltrain/wondrful.mid ">Wonderful
<OPTION VALUE="http://www.yoursite.co m/eltrain/would_i.mid">Wo uld I
<OPTION VALUE="http://www.yoursite.co m/eltrain/no-woman.mid">No Woman
<OPTION VALUE="http://www.yoursite.co m/eltrain/womnocry.mid ">Woman Cry
<OPTION VALUE="http://www.yoursite.co m/eltrain/whatislo.mid ">What
<OPTION VALUE="http://www.yoursite.co m/eltrain/stbyme.mid">Sta nd by
Your Man
<OPTION VALUE="http://www.yoursite.co m/eltrain/malovwom.mid ">Man
<OPTION VALUE="http://www.yoursite.co m/eltrain/chaingng.mid ">Chain
Gang

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

</SELECT><BR />
<OBJECT id=music height="20" width="280"
classid=clsid:2 2D6F312-B0F6-11D0-94AB-0080C74C7E95>
<PARAM NAME="AutoStart " VALUE="-1">
<PARAM NAME="Balance" VALUE="0">
<PARAM NAME="DisplaySi ze" VALUE="0">
<PARAM NAME="Filename" VALUE="">
<PARAM NAME="Mute" VALUE="0">
<PARAM NAME="Selection Start" VALUE="-1">
<PARAM NAME="Selection End" VALUE="-1">
<PARAM NAME="ShowContr ols" VALUE="true">
<PARAM NAME="ShowAudio Controls" VALUE="-1">
<PARAM NAME="ShowDispl ay" VALUE="0">
<PARAM NAME="ShowPosit ionControls" VALUE="-1">
<PARAM NAME="Volume" VALUE="0">
<PARAM NAME="AudioStre am" VALUE="-1">
<PARAM NAME="AutoSize" VALUE="0">
<PARAM NAME="Animation AtStart" VALUE="-1">
<PARAM NAME="AllowScan " VALUE="-1">
<PARAM NAME="AllowChan geDisplaySize" VALUE="-1">
<PARAM NAME="AutoRewin d" VALUE="1">
<PARAM NAME="BaseURL" VALUE="">
<PARAM NAME="Buffering Time" VALUE="5">
<PARAM NAME="Captionin gID" VALUE="">
<PARAM NAME="ClickToPl ay" VALUE="-1">
<PARAM NAME="CursorTyp e" VALUE="0">
<PARAM NAME="CurrentPo sition" VALUE="-1">
<PARAM NAME="CurrentMa rker" VALUE="0">
<PARAM NAME="DefaultFr ame" VALUE="">
<PARAM NAME="DisplayBa ckColor" VALUE="0">
<PARAM NAME="DisplayFo reColor" VALUE="16777215 ">
<PARAM NAME="DisplayMo de" VALUE="0">
<PARAM NAME="Enabled" VALUE="-1">
<PARAM NAME="EnableCon textMenu" VALUE="-1">
<PARAM NAME="EnablePos itionControls" VALUE="-1">
<PARAM NAME="EnableFul lScreenControls " VALUE="0">
<PARAM NAME="EnableTra cker" VALUE="-1">
<PARAM NAME="InvokeURL s" VALUE="-1">
<PARAM NAME="Language" VALUE="-1">
<PARAM NAME="PlayCount " VALUE="100">
<PARAM NAME="PreviewMo de" VALUE="0">
<PARAM NAME="Rate" VALUE="1">
<PARAM NAME="SAMILang" VALUE="">
<PARAM NAME="SAMIStyle " VALUE="">
<PARAM NAME="SAMIFileN ame" VALUE="">
<PARAM NAME="SendOpenS tateChangeEvent s" VALUE="-1">
<PARAM NAME="SendWarni ngEvents" VALUE="-1">
<PARAM NAME="SendError Events" VALUE="-1">
<PARAM NAME="SendKeybo ardEvents" VALUE="0">
<PARAM NAME="SendMouse ClickEvents" VALUE="0">
<PARAM NAME="SendMouse MoveEvents" VALUE="0">
<PARAM NAME="SendPlayS tateChangeEvent s" VALUE="-1">
<PARAM NAME="ShowCapti oning" VALUE="0">
<PARAM NAME="ShowGotoB ar" VALUE=0">
<PARAM NAME="ShowStatu sBar" VALUE="0">
<PARAM NAME="ShowTrack er" VALUE="-1">
<PARAM NAME="Transpare ntAtStart" VALUE="-1">
<PARAM NAME="VideoBord erWidth" VALUE="0">
<PARAM NAME="VideoBord erColor" VALUE="0">
<PARAM NAME="VideoBord er3D" VALUE="0">
<PARAM NAME="Windowles sVideo" VALUE="0">
</OBJECT>
</center>

</body>
</html>

Mar 26 '06 #3
el*********@ele ctrician.com said the following on 3/26/2006 1:37 AM:

<snip crappy useless code>
<SELECT id=cancion
onchange=docume nt.all.music.fi lename=document .all.cancion.va lue; 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.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Mar 26 '06 #4
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.

Mar 26 '06 #5
el*********@ele ctrician.com 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.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Mar 26 '06 #6
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.

Mar 26 '06 #7
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(sou ndFile)
{
this.soundFile= soundFile;
this.objRef=nul l;
this.preLoad();
}

SCmediaPlay.pro totype.removeOb j=function()
{
if(this.objRef! =null)
{
document.body.r emoveChild(this .objRef);

this.objRef=nul l;
}
}

SCmediaPlay.pro totype.playSoun d=function()
{

this.removeObj( );

this.objRef=doc ument.createEle ment('embed');

this.objRef.set Attribute("widt h","0");

this.objRef.set Attribute("heig ht","0");

this.objRef.set Attribute("hidd en","true");

this.objRef.set Attribute("src" , this.soundFile) ;

document.body.a ppendChild(this .objRef);

}

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

if(document.bod y && document.create Element)
{

/* == 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(SCm ediaTable[i].f)
document.links[ SCmediaTable[i].ind ].onmouseover=
new Function("SCobj Table["+i+"].playSound()") ;
document.links[ SCmediaTable[i].ind ].onmouseout=
new Function("SCobj Table["+i+"].removeObj()") ;
}

}
</script>

</body>
</html>

Mar 27 '06 #8
What a bunch of crap!

Mar 27 '06 #9
<Randy
comp.lang.javas cript 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!

Mar 27 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
10025
by: Rajesh Kapur | last post by:
Hello All, We are building an application that will dynamically choose and pre-pend short underwriting messages to the audio streamed over the web. We will use SMIL files. We need to decide if the short underwriting messages are better off stored in a the database (BLOB field?) or in a physical file with the references stored in the database. How can we load the audio from a physical file to the database? Is it a good idea to store...
1
1330
by: Benny | last post by:
Hi, I have written recommend a friend script in ASP which can send a form filled details to around 5 Email Ids at a time. I want people to use this with their custom voice message. Can they record and attach with this recommendation form and send that to email.
8
2775
by: fuliopen | last post by:
I like to create some audio files for my web site. These are all language files to help the visitor learn a foreign language. There is no music. As far as I know, I can create three types of such files: .wav, .mp3 and .wma. But my knowledge may be too old. Is there any new type? I've seen an indicator for audio files in some language-learning pages. It is a small trumpet. Clicking it would play the sound file. Is this small...
0
2345
by: laredotornado | last post by:
Hello, I want to play an audio file by clicking on an audio icon and not having the page switch out underneath. Right now the code I have is ... <html> <head> <title>Dictionary: homeostasis</title> <link href="liveink.css" type="text/css" rel="stylesheet"/> </head> <body>
2
2828
by: cody | last post by:
Does anybody know how to play MIDI files? I do not want to use P/Invoke or DirectX. Maybe there is a free 3rd party Library but I do not know any supporting MIDI music. I tried the library "Bass" from www.un4seen.com but MIDI music isn't supported.
22
3764
by: MLH | last post by:
I have some audio help files that play fine from within Access 97 and Access 2.0. Both are running on a Windows XP box. But I do not know what program plays the files. If I click Start, Run and type in c:\MyApp\MyHelp\Help1.wav, Windows Media Player tries unsuccessfully to play the wav file. It err's saying ClassFactory cannot supply the requested class. But WMP has no problem at all playing c:\windows\system32\ ALSNDMGR.WAV. That goes...
2
2626
by: ViperCB | last post by:
Hello from a newbie, I am trying to do some research on an upcoming project that involves reading in audio files of various formats and using the audio signal as a source of noise to generate pretty pictures. (like windows media player visual plugins. I will be developing in C++ and was wondering if there are any packaged libraries out there that I can use to read audio files encoded in different formats and lets me easily access the...
4
6057
by: Gary Morrison | last post by:
I need to create a lot of fairly-short audio files from the concatenation of a lot of even shorter audio files. I'd like to control that from a Perl script. The audio files would presumably be AIFF or WAV files, preferable AIFF. Do any of you know of Perl commands to accomplish this? Specifically, * A call to create and open a new, empty AIFF or WAV file, * A call to append onto the end of that open audio file the audio content of...
2
5063
by: gskrishnan | last post by:
I would like someone to help me with VB code for the following problem. I want to play a composed audio file of a certain beat cycle. A metronome file corresponding to the audio file beat cycle is also to be played in the background so that the user gets a feel for the synchronization. The user should be able to fully control the start, stop, volume, and tempo variation of each of the two audio files individually. Thanks in advance. ...
0
8984
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8823
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9530
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9312
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9238
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6793
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
3300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2775
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2206
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.