[英]Meteor DOMException: Unable to decode audio data
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. 编辑:我刚刚创建了一个新的流星项目,它工作:D哇。但它仍然无法在我的核心项目上工作..看起来像我有不同的设置。
In my Meteor.js project i have 4 .mp3
-files located in public/sounds/xyz.mp3
. 在我的Meteor.js项目中,我有4个.mp3
文件位于public/sounds/xyz.mp3
。 I load these .mp3
with : 我加载这些.mp3
:
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. 这个在google Chrome
,但当我通过meteor run android-device
构建应用程序时,我收到以下错误消息: DOMException: Unable to decode audio data
我不知道这是一个错误,因为加载.png
或.jpg
工作得很好在移动版中。 I have not installed any packages beside meteor add crosswalk
but deinstalling this doesnt help either. 我没有在meteor add crosswalk
旁边安装任何软件包,但卸载这个也没有帮助。
You shouldn't need to do a http request to get a local resource. 您不需要执行http请求来获取本地资源。 You can just refer to a local url. 您可以参考本地网址。 On the Android device the path is different. 在Android设备上,路径是不同的。 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 Android设备不支持此Web API,但适用于Android的chrome浏览器
Check browser specification in this link https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/decodeAudioData 检查此链接中的浏览器规范https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/decodeAudioData
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.