[英]No sound in Phaser 3 app when using Capacitor to build for iOS
我创建了一个简单的Phaser 3测试应用程序(在 Typescript 中,使用rollup
转译),并且正在使用Capacitor将其转换为我的 Mac 上的 iOS 应用程序。
这是应用程序的相关部分:
function preload () {
this.load.audio('boom', ['boom.mp3', 'boom.ogg', './boom-44100.ogg', './boom-44100.mp3']);
this.load.image('wizball', './wizball.png');
}
function create () {
const image = this.add.image(400, 300, 'wizball').setInteractive();;
this.boom = this.sound.add('boom');
image.on('pointerup', () => {
this.boom.play();
});
}
该应用程序显示一个wizball的图像,如果您单击它,您会听到“boom”。
当我运行它时:
npm run watch
,在我的 Mac 上的浏览器中使用 http://localhost:10001 ,它工作正常;dist/
目录中加载index.html
,它工作正常;这些是生成 iOS 应用程序的步骤:
npm i
npm run watch
npx cap add ios
npx cap copy ios
npx cap open ios
Xcode 中的控制台日志显示以下错误:
Error: There is no audio asset with key "boom" in the audio cache
⚡️ URL: capacitor://localhost/game.js
我觉得这很奇怪,因为可以很好地找到图像资产。 在ios/App/public/
目录中, boom.mp3
和wizball.png
都存在。
我已经把完整的代码和重现步骤放在了这里: https : //github.com/joostvunderink/soundtest你需要安装 node 10+ 和 Xcode(至少配置一个虚拟设备)来构建 iOS 应用程序。
我在看什么?
在你的游戏配置中禁用网络音频,添加到你的游戏配置底部,就像这样。
let game = new Phaser.Game({
...
audio: {
disableWebAudio: true
}
});
警告:
此问题的另一种解决方法是:
有同样的问题。 我发现只有使用 ios 平台移相器加载器才能在声音加载时解析 ArrayBuffer。 这就是为什么我使用简单的获取加载音频并使用 scene.sound.decodeAudio 添加到移相器。 类似的东西:
fetch(sound.url)
.then((response) => response.arrayBuffer())
.then((response) => {
scene.sound.decodeAudio({
data: response,
key: 'audioKey',
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.