gre*_*sin 9 javascript audio cordova meteor
编辑:我刚刚创建了一个新的流星项目,它工作:D哇.但它仍然无法在我的核心项目上工作..看起来像我有不同的设置.
在我的Meteor.js项目中,我有4个.mp3文件位于public/sounds/xyz.mp3.我加载这些.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();
Run Code Online (Sandbox Code Playgroud)
这个工作google Chrome,但当我通过构建应用程序时meteor run android-device,我收到以下错误消息:DOMException: Unable to decode audio data
我想知道这是一个错误,因为加载.png或.jpg在移动版本中工作得很好.我没有安装任何软件包,meteor add crosswalk但卸载这也没有帮助.
您不需要执行http请求来获取本地资源.您可以参考本地网址.在Android设备上,路径是不同的.看到这段代码:
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();
}
}
Run Code Online (Sandbox Code Playgroud)
在设备上,它以异步方式加载声音文件,然后播放它.在浏览器中,它只是加载并同步播放.
Android 设备不支持此 Web API,但适用于 Android 的 chrome 浏览器
检查此链接中的浏览器规范 https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/decodeAudioData
| 归档时间: |
|
| 查看次数: |
926 次 |
| 最近记录: |