ie8 fix
madison

Hardware 2.0

Adrian Kingsley-Hughes

JavaScript decoder for MP3 - No Flash!

By | June 20, 2011, 2:46am PDT

The other day I linked to code that Mozilla is hoping to bake into the Firefox browser to natively handle PDF documents, today let’s look at an example of JavaScript code that will decode MP3 files.

That’s right, MP3 support with no Flash needed! I like! I like!

This is pretty cool. At present it’s pretty limited in that it only works out-of-the-box in Firefox 4/5/6 (and Mozilla’s concept browser Aurora). There’s support in Chrome 12 Dev (Linux), Chrome 12 (OSX) and Chrome Canary (Windows) as long as you enable ‘Web Audio API‘ in ‘about:flags‘ (as long as you can tolerate the distortion as Chrome forces the samplerate to 48,000Hz). There’s also no support for the necessary Audio Data and Web Audio APIs in Internet Explorer, Opera, Safari, Mobile Safari or Android Browser so it doesn’t work.

There are a lot of future improvements in the pipeline - Chrome 10+ support, MPEG Layer 1/2/2.5 support, support for ID3v2.2 and v2.3 fully and buffering.

HTML 5 is going to make the web browser an even more powerful tool.

Code available on GitHub.

Kick off your day with ZDNet's daily e-mail newsletter. It's the freshest tech news and opinion, served hot. Get it.

Topics

Adrian Kingsley-Hughes is an internationally published technology author who has devoted over a decade to helping users get the most from technology.

Disclosure

Adrian Kingsley-Hughes

All opinions expressed on Hardware 2.0 are those of Adrian Kingsley-Hughes. Every effort is made to ensure that the information posted is accurate. If you have any comments, queries or corrections, please contact Adrian via the email link here. Any possible conflicts of interest will be posted below. [Updated: February 23, 2010] - Adrian Kingsley-Hughes has no business relationships, affiliations, investments, or other actual/potential conflicts of interest relating to the content posted so far on this blog.

Biography

Adrian Kingsley-Hughes

Adrian Kingsley-Hughes is an internationally published technology author who has devoted over a decade to helping users get the most from technology -- whether that be by learning to program, building a PC from a pile of parts, or helping them get the most from their new MP3 player or digital camera.

Adrian has authored/co-authored technical books on a variety of topics, ranging from programming to building and maintaining PCs. His most recent books include "Build the Ultimate Custom PC", "Beginning Programming" and "The PC Doctor's Fix It Yourself Guide". He has also written training manuals that have been used by a number of Fortune 500 companies.

Adrian also runs a popular blog under the name The PC Doctor, where he covers a range of computer-related topics -- from security to repairing and upgrading.

Related Discussions on TechRepublic

Did you know you can take part in these discussions with your ZDNet membership?
15
Comments

Join the conversation!

Just In

RE: JavaScript decoder for MP3 - No Flash!
aikeru@... 24th Jun
@thx-1138_@... JavaScript IS better than flash, IMO.
By using JavaScript/HTML5 to do these things, you only have to worry about the security of JavaScript/HTML5.
A browser-maker must wait on Adobe to patch Flash, unless they maintain it themselves which requires resources and time that would be better spent improving the browser. Flash, as a 3rd party plug-in, MUST run outside of the (normal) browser sandbox, because flash requires 3rd party executable code.
You could argue that people might make websites that have ads completely in JavaScript and that you couldn't turn them off because the website's functionality depends on it ... but the situation is really no different than what we have today, IMO.
What's going to stop "me" from creating a site that depends on flash AND has flash advertisements?
What's going to stop "me" from creating a site NOW that depends on JavaScript and has JavaScript ads?
Ad-blocking will find ways to get smarter -- I don't know if it will be script hashes, or blocking script signatures, or selectively enabling parts of the API or blocking scripts pulled from certain domains or something I haven't ever thought of (no doubt the latter :)). I would much rather have a standard spread across browsers and have that kind of choice (and as a developer, power) versus a plugin that users are forced to download that runs 3rd party code.
0 Votes
+ -
If you experimented with the range of MP3/MP4 players
Dietrich T. Schmitz, *~* Your Linux Advocate 20th Jun
on Linux,

mplayer is the best.
I have this plugin installed in FF4, so far so good.
Isn't NoScript the #1 add-in for FireFox? Do people not remember X-10 camera pop-under ads and all the other reasons that script blockers came into being and became popular?

Meet the new Flash, same as the old Flash. People act like getting rid of Flash is going to be some giant victory over advertising and malware. Not if it gets replaced with another scripting language.
0 Votes
+ -
Compromise
facebook@... 20th Jun
@Robert Hahn People need to find the right balance between functionality and security. Javascript will probably be the largest attack vector in 3-4 years. Javascript exploits are poised to affect multiple operating systems, whether they use monolithic kernels or hybrid kernels.

However, having said that, what is the alternative? the death of the web browser all together?
@facebook@... ... need much else than that. So no pop-ups, no blinking ads (iAds do not pop-up and do not blink, and Apple prohibits use of pop-ups and blinks for Google's AdSense ads that built-in in Apps).
0 Votes
+ -
what is the alternative? One alternative is to accept the tradeoff you describe between functionality and security. You know it's there; I know it's there. Replacing one scripting language with another does not make the tradeoff go away. What we know for sure is that any software system that achieves widespread adoption (Windows, Flash, SQL) will attract miscreants. JavaScript was one of those; the Bad Guys went elsewhere because so many people were blocking it. If the blockers go away, the Bad Guys will be back.
There is something inherently dangerous in code that seamlessly executes across platofrms (java and javascript).

The alternative is to allow choice. Perhaps the JS MP3 player and previously mentioned JS PDF reader should be plugins or extensions, not mandatory integrated parts of the browser.

Further choice needs to be offered by browser creators so that the user can basically strip the thing bare of functionality if desired.

Some might find it surprising that NCSA Mosaic running on a 15 year old DEC Alpha renders many websites just fine. It has no idea what JS is and ignores it.

I'm not advocating users go back to old or esoteric systems, but I advocate a complete choice of function level. It is partially available by the aforementioned NoScript, and others like Netticat's Better Privacy (flask cookie killer). Thank God for programmers who like the user to have control and privacy, not the corporation control it.

Javascript is much more prevalent than it needs to be. Sometimes it is used for communication with a stat counter or analytics, but If i am not doing commerce with the website, I don't want to be counted or analyzed thank you. JS is also used a lot for dealing with forms, trying to "hide" things, and the like. It is as much webmasters' responsibility for using javascript where it is not necessary, where the "application behind the form" could as well control things in the server. Javascript is also seen as a way to offload some of the website's work for that session onto the guest's browser and this is a huge security hole.

So while flash is evil (because of the spying cookies they were caught trying to hide), is javascript going to make anything better? It will make it different. If, unlike Flash, it is forcibly made part of the browser, then it will be worse.
0 Votes
+ -
Yep, that sounds logical and correct
thx-1138_@... 20th Jun
@opcom "... If, unlike Flash, it is forcibly made part of the browser, then it will be worse."

I completely agree it's just a permutation on an existing vector (avenue) for attack. The dynamics have shifted, but the vulnerabilities will still be inherent.
0 Votes
+ -
@thx-1138_@... JavaScript IS better than flash, IMO.
By using JavaScript/HTML5 to do these things, you only have to worry about the security of JavaScript/HTML5.
A browser-maker must wait on Adobe to patch Flash, unless they maintain it themselves which requires resources and time that would be better spent improving the browser. Flash, as a 3rd party plug-in, MUST run outside of the (normal) browser sandbox, because flash requires 3rd party executable code.
You could argue that people might make websites that have ads completely in JavaScript and that you couldn't turn them off because the website's functionality depends on it ... but the situation is really no different than what we have today, IMO.
What's going to stop "me" from creating a site that depends on flash AND has flash advertisements?
What's going to stop "me" from creating a site NOW that depends on JavaScript and has JavaScript ads?
Ad-blocking will find ways to get smarter -- I don't know if it will be script hashes, or blocking script signatures, or selectively enabling parts of the API or blocking scripts pulled from certain domains or something I haven't ever thought of (no doubt the latter :)). I would much rather have a standard spread across browsers and have that kind of choice (and as a developer, power) versus a plugin that users are forced to download that runs 3rd party code.
0 Votes
+ -
RE: JavaScript decoder for MP3 - No Flash!
Gabriel Hernandez Updated - 20th Jun
binary code can be embedded in javascript very easily, this could be used to implement great multimedia features for the browser:
audio support (midi, mp3, wav encoder/decoders),video support (avi, mov or divX encoder/decoders) and also network features with WebSockets (p2p programs) but there is a risk:
Viruses and malware. There could be a need to implement an antivirus for javascript code, which would be difficult to implement since there are no previous antiviruses built for the javascript programming language.
0 Votes
+ -
RE: JavaScript decoder for MP3 - No Flash!
Dan McTaggart Updated - 20th Jun
Got my flash mp3 player working. Need some finished code that works in all browsers before I"ll consider asking my provider of the flash player to switch.
0 Votes
+ -
RE: JavaScript decoder for MP3 - No Flash!
Dan McTaggart Updated - 20th Jun
Blackberry Playbook shows perfected flash.
Flash is all over the place.
Javascript is the most powerful scripting language.
Javascript is like glue, very handy if you need it.
Adobe Javascript? hmmm Maybe javascript will finally
find it's place as the most powerful scripting language
and the glue of the web. It's elegant, but only for those
who truly know the awesome power locked inside it.
Kinda like looking at a Ferrari engine as a novice and saying, boy I'd like to make one of those! Someone like Adobe needs to take the bull by the horns and get the best javascript guys they can find and really put the code into javascript objects that can be easily used.
Otherwise we'll be debugging forever. You know it. There are a gazillion javascript hackers in the world.
So that's the state of the web. Starting to put together something that should have been started in 1995. Oh well, better late than never.
0 Votes
+ -
Already done
Robert Hahn 20th Jun
You are describing Flash. The differences between JavaScript and Flash's ActionScript are minimal; both are flavors of ECMAScript. Adobe's class library for Flash is huge.
0 Votes
+ -
RE: JavaScript decoder for MP3 - No Flash!
Dan McTaggart Updated - 20th Jun
@Robert Hahn Precisely, and RIM's Blackberry Playbook proves it works flawlessly. Of course QNX I/O makes it
the perfect machine. Too bad it doesn't come in a desktop.
I was thinking of getting one of those stands and a bluetooth keyboard and making it my new PC. Ah well. Thanks for the reply. I hear the new Windows 8 core is 25MB. In 1995 QNX fit on a floppy disk.
Just FYI, "Aurora" is not something different from Firefox 5 or 6.

With Mozilla's new release process, there are three (well, four if you count final releases) development channels in order of stability: Nightly, Aurora, and Beta. Version numbers don't match up to a single channel.
Nightly channel is like the old Minefield builds, and is not guaranteed to be stable. It is currently at version 7.

Aurora is somewhere between the old alpha and beta builds, more likely to be stable than Nightly, but still no guarantees. Aurora is currently on version 6.
Beta is somewhere between the old beta and release candidate builds, where it's practically the final release, but things could still change.

Beta is currently on version 5. (But that will change when Beta gets pushed out officially as Firefox 5 on the 21st.)
0 Votes
+ -
RE: JavaScript decoder for MP3 - No Flash!
Dan McTaggart Updated - 20th Jun
Project Rate 44100

nuff said

Join the conversation!

Formatting +
BB Codes - Note: HTML is not supported in forums
  • [b] Bold [/b]
  • [i] Italic [/i]
  • [u] Underline [/u]
  • [s] Strikethrough [/s]
  • [q] "Quote" [/q]
  • [ol][*] 1. Ordered List [/ol]
  • [ul][*] · Unordered List [/ul]
  • [pre] Preformat [/pre]
  • [quote] "Blockquote" [/quote]
ie8 fix
Click Here
ie8 fix

The best of ZDNet, delivered

ZDNet Newsletters

Get the best of ZDNet delivered straight to your inbox

Facebook Activity

White Papers, Webcasts, & Resources
ie8 fix
ie8 fix