【发布时间】:2022-01-10 01:50:43
【问题描述】:
也许你可以帮帮我,我一直在寻找所有信息,以解决我的这个问题,但没有,我无法使用cordova的播放器......
实际上我无法加载mp3文件,无论是本地还是远程,我总是得到这个错误:“错误:缓冲区未设置或未加载”,路径中的文件在那里。
我尝试使用 Tone 的示波器查看是否在加载 Tone 时遇到问题,但效果很好。
这是否取决于某些授权,特别是我可能会丢失?
例如使用cordova媒体插件我可以重现音频,但我需要使用Tonejs。
你有什么想法,这可能取决于什么。或者我可以尝试做什么? ...
即使是这个简单的例子,设备准备好后也不去:
const player = new Tone.Player("https://tonejs.github.io/audio/berklee/gong_1.mp3") .toDestination();
Tone.loaded().Then(() => {
player.start ();
});
已经与 Tone 和 Cordova 合作过的各位,希望它可以以某种方式使用,如果您有任何想法,请提前告诉我!
--- 更新:
目前,当应用程序启动时,我的行为是这样的(我声明它是为网站开发的代码的移植,并且一切正常加载它等等):
let myLoader_File = function functionOne(test) {
var androidFixPath = cordova.file.applicationDirectory
console.log("Entered function");
return new Promise((resolve, reject) => {
let CaricatorePlayers = new Tone.Players({
Beep: androidFixPath + "sample/Beep.mp3",
Clave: androidFixPath + "sample/Clave.mp3",
}).toDestination();
resolve(
CaricatorePlayers
//"ok tutti i file sono stati caricati!"
);
reject("si è verificato un errore!");
});
};
function onDeviceReady() {
$('#fade-wrapper-flash').fadeOut(1000);
$('#fade-wrapper').fadeIn();
//attach a click listener to a start button
document.querySelector('#fade-wrapper').addEventListener('click', async () => {
await Tone.start();
console.log('audio is ready');
myLoader_File().then((res) => {
console.log(`The function recieved with value ${res}`)
MultiPlayers = res;
console.log(MultiPlayers)
try {
// Play
MultiPlayers.player("Beep").start();
$('#fade-wrapper').fadeOut();
preLoad();
} catch (error) {
console.log(error);
console.log("IN ERRORE RICARICO");
}
}).catch((error) => {
console.log(`Handling error as we received ${error}`);
console.log("IN ERRORE RICARICO");
$('#fade-wrapper').fadeIn();
});
});
}
【问题讨论】:
-
通常在最终用户与您的 webview 交互之前,您无法拥有声音缓冲区,可能是这种情况吗?
-
谢谢@Eric ...从这个角度来看,我认为我没有任何问题,启动过程是这样的:我已经准备好设备,我在其中初始化一个监听器以进行点击用户,然后我调用一个函数来加载播放器(现在我在问题中添加代码)。
标签: android cordova buffer mp3 tone.js