最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Meteor DOMException: Unable to decode audio data - Stack Overflow

programmeradmin3浏览0评论

EDIT : I just created a new Meteor Project and it worked :D wow.But it still doesnt work on my core project..looks like i have different settings.

In my Meteor.js project i have 4 .mp3-files located in public/sounds/xyz.mp3. I load these .mp3 with :

 let soundRequest = new XMLHttpRequest();
    soundRequest.open('GET', this._soundPath, true);
    soundRequest.responseType = 'arraybuffer';
    let $this = this;
    soundRequest.onload = function () {
        Core.getAudioContext().decodeAudioData(soundRequest.response, function (buffer) {
            $this.source.buffer = buffer;
            $this.source.loop = true;
            $this.source.connect($this.panner);
        });
    };
soundRequest.send();

This WORKS on google Chrome, but when i build the app via meteor run android-device, i get the following error message : DOMException: Unable to decode audio data I wonder if this is a bug because loading .png or .jpg works just fine in the mobile version. I have not installed any packages beside meteor add crosswalk but deinstalling this doesnt help either.

EDIT : I just created a new Meteor Project and it worked :D wow.But it still doesnt work on my core project..looks like i have different settings.

In my Meteor.js project i have 4 .mp3-files located in public/sounds/xyz.mp3. I load these .mp3 with :

 let soundRequest = new XMLHttpRequest();
    soundRequest.open('GET', this._soundPath, true);
    soundRequest.responseType = 'arraybuffer';
    let $this = this;
    soundRequest.onload = function () {
        Core.getAudioContext().decodeAudioData(soundRequest.response, function (buffer) {
            $this.source.buffer = buffer;
            $this.source.loop = true;
            $this.source.connect($this.panner);
        });
    };
soundRequest.send();

This WORKS on google Chrome, but when i build the app via meteor run android-device, i get the following error message : DOMException: Unable to decode audio data I wonder if this is a bug because loading .png or .jpg works just fine in the mobile version. I have not installed any packages beside meteor add crosswalk but deinstalling this doesnt help either.

Share Improve this question edited Jan 26, 2017 at 17:04 greedsin asked Jan 24, 2017 at 12:32 greedsingreedsin 1,2722 gold badges27 silver badges49 bronze badges 3
  • can you post plete error or stacktrace here? – Akshay Tilekar Commented Jan 30, 2017 at 11:28
  • Read this : developer.mozilla/en-US/docs/Web/API/AudioContext/… – Akshay Tilekar Commented Jan 30, 2017 at 13:16
  • @lolio did you had a chance to look at this link - stackoverflow./questions/38589614/… Chunking the stream could probably work – Gandhi Commented Jan 31, 2017 at 6:33
Add a ment  | 

2 Answers 2

Reset to default 5

You shouldn't need to do a http request to get a local resource. You can just refer to a local url. On the Android device the path is different. See this code:

  function getSound(file) {
    var sound = "/sounds/"+file;
    if (Meteor.isCordova) {
      var s;
      if (device.platform.toLowerCase() === "android") {
        sfile = cordova.file.applicationDirectory.replace('file://', '') + 'www/application/app' + sound;
      }
      else {
        sfile = cordova.file.applicationDirectory.replace('file://', '') + sound;
      }
      var s = new Media(
        sfile,
        function (success) {
          console.log("Got sound "+file+" ok ("+sfile+")");
          s.play();
        },
        function (err) {
          console.log("Get sound "+file+" ("+sfile+") failed: "+err);
        }
      );
    } else {
      var a = new Audio(sound);
      a.play();
    }
  }

On a device it loads the sound file asynchronously and then plays it. In the browser it just loads and plays it synchronously.

This web API is not supported on android device but works on chrome browser of android

Check browser specification in this link https://developer.mozilla/en-US/docs/Web/API/AudioContext/decodeAudioData

发布评论

评论列表(0)

  1. 暂无评论