I have created a simple Phaser 3 test app (in Typescript, with rollup to transpile) and am using Capacitor to convert it into an iOS app on my Mac.
This is the relevant part of the app:
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();
});
}
The app shows an image of a wizball, and if you click it, you hear "boom".
When I run it:
- With
npm run watch, using http://localhost:10001 in a browser on my Mac, it works fine; - By loading
index.htmlin thedist/dir in a browser on my Mac, it works fine; - By loading https://garion.org/soundtest-ts/ on either my Mac or my iPad, it works fine;
- But when I use Capacitor to build an iOS app in Xcode, clicking the image gives no sound at all.
These are the steps to generate the iOS app:
npm i
npm run watch
npx cap add ios
npx cap copy ios
npx cap open ios
The console log in Xcode shows the following error:
Error: There is no audio asset with key "boom" in the audio cache
⚡️ URL: capacitor://localhost/game.js
I find this strange, because the image asset can be found just fine. In the ios/App/public/ dir, both boom.mp3 and wizball.png are present.
I have put the full code, with steps to reproduce, here: https://github.com/joostvunderink/soundtest You will need node 10+ and Xcode (with at least one virtual device configured) installed to build the iOS app.
What am I overlooking?