2

If you want to decode Audio Data, createMediaElementSource() is not working on mobile devices, However createBufferSource() method is working properly:

This code is working properly in web browsers, but not in mobile devices:

var audioSource = new Audio();
audioSource.src= "Test.mp3";
var audioCtx = new AudioContext();
var sourceT1 = audioCtx.createMediaElementSource(audioSource); //This is the source audio
//My Decoding...

And this code is working for both Web and Mobile browsers:

var audioSource = new Audio();
var audioCtx = new AudioContext();
var sourceT2 = audioCtx.createBufferSource(); //This is the source audio
request = new XMLHttpRequest();
request.open('GET', 'Test.mp3', true);
request.responseType = 'arraybuffer';
request.onload = function() {
 var audioData = request.response;
audioCtx.decodeAudioData(audioData, function(myBuffer) {
 sourceT2.buffer = myBuffer;
//My Decoding...
 },
function(e){"Error with decoding audio data" + e.err});
}

In my case I have an Audio source that comes from a video player to be decoded, which is a MediaElementAudioSourceNode, and I need to convert it to a AudioBufferSourceNode in order to get my code working on mobile devices, In other words, is it possible to convert sourceT1 to sourceT2?

Any Idea how to do it?

EDIT: Based on this answer, unfortunatly I think it is impossible to do it

Nourdine Alouane
  • 804
  • 12
  • 22
  • 1
    I think as well it's mission impossible as it is not supported. – Kilian Hertel Apr 24 '16 at 09:10
  • Which video files do you need to access? Can u use file-api? What do you want to do with the audio afterwards? Perhaps there is another way... – Kilian Hertel Apr 24 '16 at 09:12
  • I need to get the byte frequency of a remote audio streaming, the problem is that getByteFrequencyData() doesn't work in mobile devices when I create the media by using createMediaElementSource(). Right now I'm trying to find another way, do you know any solution for visualizing frequency of a streaming audio (.m3u8)? – Nourdine Alouane Apr 25 '16 at 10:37

1 Answers1

0

You don't say, but if you're using Chrome, createMediaElementSource should be working now. You have to go to chrome://flags and enable the unified media pipeline flag first, though.

Raymond Toy
  • 5,490
  • 10
  • 13