0

The following JavaScript running in canvas should play audio fine:

var audio = new Audio('tune.wav'); audio.play(); 

Most of the time it does work, the wav is 24bit 14100kbps and plays fine on several machines, but on my laptop (Win7, using Firefox 22.0) I get the error:

  • HTTP "Content-Type" of "x-unknown/unknown" is not supported. Load of media resource file:///C:/code/sound/tune.wav failed.

I'm aware that there are other libraries to play sound, but I want to keep this pure JavaScript and since it works fine on other machines it might be a hardware problem. But I am able to play other audio files fine, so I'm not sure what's going wrong here. Any ideas?

1 Answer 1

2

Hmm. Based upon my experience with the JS Audio elements, you're missing a line.

var audio = new Audio('tune.wav'); audio.load(); audio.play(); 

I don't think that's causing the error though. Based upon the responses to this question:

Firefox won't play .WAV files using the HTML5 <audio> tag?

and the back-and-forth in this forum: https://bugzilla.mozilla.org/show_bug.cgi?id=524109 (comment 7)

It looks like Firefox simply doesn't support 24-bit WAVE files. 16-bit is probably a safer option.

Sign up to request clarification or add additional context in comments.

1 Comment

I obviously missed out the audio.load() and have switched the wavs to 8 bit. However the problem continued to occur when testing local files. Testing the exact same files using Mongoose, as a local-host, and the sound worked fine. Which I can't explain.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.