Question

I'm interested in using the Web Audio API. Unfortunately my audio files are are all in an esoteric format that Chrome can't decode. (They're .wavs, but sampled at 96 kHz with 32-bit float encoding.)

Is there any way for me to query my browser (Chrome) to find out exactly which audio formats and encodings it supports?

UPDATE

I've found a list of file formats supported by Chrome here: https://sites.google.com/a/chromium.org/dev/audio-video

Was it helpful?

Solution

You could test this sort of thing by trying to load a variety of sample files using a try...catch construct, and seeing which filetypes load and which don't. See this tutorial for loading files with the Web Audio API in Chrome.

OTHER TIPS

There is! I don't know how reliable this is, but...

// Need to check the canPlayType first or an exception
// will be thrown for those browsers that don't support it      

var myAudio = document.createElement('audio'); 

if (myAudio.canPlayType) {
   // Currently canPlayType(type) returns: "", "maybe" or "probably" 
   var canPlayMp3 = !!myAudio.canPlayType && "" != myAudio.canPlayType('audio/mpeg');
   var canPlayOgg = !!myAudio.canPlayType && "" != myAudio.canPlayType('audio/ogg; codecs="vorbis"');
}

Since we're talking about WAV files here, I would use these:

audio/vnd.wave, audio/wav, audio/wave, audio/x-wav

The best thing to do is to figure out what your file's MIME type is (should be one of the above), and then check for that with something like this:

var canPlayWav = !!myAudio.canPlayType && "" != myAudio.canPlayType('MIME_TYPE_HERE');
if (canPlayWav) { dothis(); } else { dothat(); }

I hope this helps!

Source: http://html5doctor.com/native-audio-in-the-browser/

A non-programmatic way would be those sites:

Using Lo-Dash:

(function(){
  var a = document.createElement('audio'),
      types = _(navigator.mimeTypes).pluck('type'),
      isAudio = /^audio\//, canPlay = {};
  if (a && a.canPlayType) {
    types
      .push('audio/flac', 'audio/opus', 'audio/webm', 'audio/ogg', 'audio/midi')
      .flatten()
      .uniq()
      .each(function(type){
        if (isAudio.test(type)) {
          canPlay[type] = !!a.canPlayType(type);
        }
      });
  }
  return canPlay;
})();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top