MobileChromeApps / chrome-app-developer-tool

Mirror of Apache Cordova app harness
Other
202 stars 33 forks source link

<audio> elements fail to load/play content #42

Open kennystrawnmusic opened 9 years ago

kennystrawnmusic commented 9 years ago

As per @Swader's report in the CDE bug tracker,

mmocny commented 9 years ago

This is related to MobileChromeApps/mobile-chrome-apps/issues/184 I think.

In the mean time, as a workaround, you can play local files programmatically by loading them with XHR and using an audioContext:

    var audioCtx = new window.AudioContext;
    function play(url) {
      var request = new XMLHttpRequest();
      request.open('GET', url, true);
      request.responseType = 'arraybuffer';

      request.onload = function() {
        audioCtx.decodeAudioData(request.response, function(buffer) {
          var source = audioCtx.createBufferSource();
          source.buffer = buffer;
          source.connect(audioCtx.destination);
          source.start(0);
        }, function(e) {
          console.log('Error decoding audio', e);
        });
      }

      request.send();
    }

(Note: do make sure not to create a new audioContext each time, as there is a firm limit on how many can be open)

Swader commented 9 years ago

What is the status of this? Will it be fixed in the foreseeable future, or should we rely on the workaround?