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.
- 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
2 Answers
Reset to default 5You 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