473,763 Members | 7,044 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
20 3256
el*********@ele ctrician.com said the following on 3/27/2006 12:12 AM:
<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 .
Maybe, maybe not. But that is not my library. Had you read it, and did a
little research on it, you would have know it was Matt Kruse's library
site. Or did you miss the image in the top left corner of the
bestpractices page that says "Matt Kruse's Javascript Toolbox"?
I see from you bio that you started in 1993.
Again, that isn't my bio.
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 in 44 years you haven't learned to write efficient code?
Experienced Idiots are still Idiots.
And you call me stupid?
Actually, what I said was "You really are as stupid as you act" and as
long as you act stupid, my opinion of you will stay that way. Want me to
think of you as intelligent? Then act that way.
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.


Again, they are not my libraries. If you bothered to research at all you
would know that I am probably the *last* person in this group to use a
library as I don't care for them. I prefer a single, one off, solution
to a specific problem. Always have and probably always will.

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Mar 27 '06 #11
In message <11************ *********@e56g2 000cwe.googlegr oups.com>,
Stephen Chalmers <ig******@lycos .co.uk> writes
How can I play midi and/or audio files using JavaScript?


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


Thanks Stephen, you clearly understood the question. An answer that
doesn't involve HTML tags.

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 27 '06 #12

el*********@ele ctrician.com wrote:
What a bunch of crap!


That certainly would be reaction of any interpreter to 'your' solution.

You might want to pass that on to the Hispanic from whom you stole it.

--
S.C.

Mar 27 '06 #13

"Stephen Kellett" <sn***@objmedia .demon.co.uk> schrieb im Newsbeitrag
news:Bx******** ******@objmedia .demon.co.uk...
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 :-)


Try a shockwave of flash object that plays the file for you. This is
the most x-browser compatible solution.
Mar 27 '06 #14
Stephen Chalmers wrote:
Stephen Kellett wrote:
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>


Not Valid. <URL:http://validator.w3.or g/>
[...]
<a href='#'>Blip</a> - <a href='#'>Ding</a> - <a href='#'>Dumb</a> - <a
href='#'>Dumb</a> - <a href='#'>Chime</a>
Displays even if client-side script support and DOM support is not
available.
[...]
SCmediaPlay.pro totype.playSoun d=function()
{

this.removeObj( );

this.objRef=doc ument.createEle ment('embed');
There is no `embed' element in HTML, so this is not supposed to work in a
standards compliant UA. And any UA that supports DOM Level 2 Core should
also support the standards compliant `object' element, so you should create
that.

You do not do any feature test, which is error-prone.

<URL:http://pointedears.de/scripts/test/whatami#inferen ce>
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) ;
Neither of this is supposed to work. Especially, setAttribute() is known
to have buggy implementations . Both the proprietary `embed' element and
the standards compliant `object' element have `param' child elements that
should be used. (Otherwise there is no sound with certain non-common
plugins, such as the mplayer-plugin on GNU/Linux.)
[...]
document.write( "<embed src='"+this.sou ndFile+"' hidden='true'
autostart='fals e' width='0' height='0'>");


See above.
PointedEars
Mar 27 '06 #15
Stephen Kellett wrote:
[...] Stephen Chalmers <ig******@lycos .co.uk> writes
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:


Thanks Stephen, you clearly understood the question.


It is not a question of understanding the question. It is about
knowing (or not knowing) that there is no such API yet as it would
have to access different plugins, some of which not even provide
an ECMAScript language binding. Standardization of plugins has
started, but is not finished yet. So solutions are all based on
speculation.
An answer that doesn't involve HTML tags.


Yet it is a solution for a certain kind of Web browsers (not
standards compliant) and a certain kind of plugins (Windows Media
Player). Nothing that qualifies as viable in a Web context.
PointedEars
Mar 27 '06 #16

Thomas 'PointedEars' Lahn wrote:
Stephen Chalmers wrote:
<a href='#'>Blip</a> - <a href='#'>Ding</a> - <a href='#'>Dumb</a> - <a
href='#'>Dumb</a> - <a href='#'>Chime</a>
Displays even if client-side script support and DOM support is not
available.
That was the intention. Presumably in practice the links would actually
go somewhere regardless.
[...]
SCmediaPlay.pro totype.playSoun d=function()
{

this.removeObj( );

this.objRef=doc ument.createEle ment('embed');
There is no `embed' element in HTML, so this is not supposed to work in a
standards compliant UA. And any UA that supports DOM Level 2 Core should
also support the standards compliant `object' element, so you should create
that.


It's a matter of what can be made to work. You should know that the
existence of standards does not mean that they can be relied upon
unconditionally . One has to work with what is known to exist.

I tried to use 'object' but IE wouldn't hide the plugin. Is there a
standard for that?

You do not do any feature test, which is error-prone.
if(document.bod y && document.create Element)

The way things are now, I considered the above to be adequate. If
course if someone knows different...

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) ;

Neither of this is supposed to work.
Is that according to a standard or just folklore? As far as I could
test, it does.
Especially, setAttribute() is known
to have buggy implementations .


Initially I tried to avoid using setAttibute, but it didn't work on one
browser.
I can test only within the scope of platforms and software available to
me.

--
S.C.

Mar 27 '06 #17
In message <48************ @individual.net >, Gernot Frisch
<Me@Privacy.net > writes
Try a shockwave of flash object that plays the file for you. This is
the most x-browser compatible solution.


Thank you.

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 27 '06 #18
In message <94************ ****@PointedEar s.de>, Thomas 'PointedEars'
Lahn <Po*********@we b.de> writes
Stephen Kellett wrote:
Yet it is a solution for a certain kind of Web browsers (not
standards compliant) and a certain kind of plugins (Windows Media
Player). Nothing that qualifies as viable in a Web context.


Given that that identifies 90% of the target market, it does qualify as
viable in a web context. I'd rather have 100% and platform neutral, but
90% is good enough (*). But really what I wanted was a simple javascript
API as I described, and this was the only answer that got close.

I think the real answer is that none exists yet. Which is a shame and
thus I have to consider using the Flash/Shockwave solution suggested by
another poster.

Thank you to all that answered.

Stephen
(*) I asked the question so I get to decide what % qualifies.
--
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 27 '06 #19
Stephen Kellett wrote:
[...] Thomas 'PointedEars' Lahn [...] writes
Yet it is a solution for a certain kind of Web browsers (not
standards compliant) and a certain kind of plugins (Windows Media
Player). Nothing that qualifies as viable in a Web context.


Given that that identifies 90% of the target market, it does qualify
as viable in a web context. [...]


Your figures are wrong, and they do not matter.
PointedEars
Mar 27 '06 #20

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

Similar topics

4
10026
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
1331
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
2830
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
3767
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
6058
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
5066
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
10144
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...
0
9997
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9937
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
8821
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5270
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5405
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3917
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
3
3522
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2793
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.