0

I want to decode .ogg contents into an ArrayBuffer.

I have following code in my Angular application component:

ngOnInit() {
  (window as any).AudioContext = (window as any).AudioContext || (window as any).webkitAudioContext;
  this.audioContext = new AudioContext();
}

myFunction(oggArrayBuffer) {
  this.audioContext.decodeAudioData(oggArrayBuffer, function(buffer) {
    console.log('decoded audio data', buffer);
  },
  function(e) { console.log('Error with decoding audio data', e); });
}

This works on Chrome, but on Safari 11, the error is being triggered:

Error with decoding audio data null

What could I be missing?

user5155835
  • 4,392
  • 4
  • 53
  • 97

1 Answers1

1

As of today, Safari still doesn't support decoding OGG files with decodeAudioData(). Since every browser supports a different set of codecs I can only recommend Decode this! to check the support of various file types directly in a browser.

The Web Audio API doesn't require the browsers to support each and every codec which is why the codec support differs from browser to browser. But browsers are required to reject decodeAudioData() with an EncodingError in case they can't decode something. Safari does just reject null for some files which is a bug. If you want Safari to behave consistently you could use standardized-audio-context which has a fix for that.

chrisguttandin
  • 7,025
  • 15
  • 21