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.
2 Answers
Answers 1
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.
Answers 2
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.org/en-US/docs/Web/API/AudioContext/decodeAudioData
0 comments:
Post a Comment