I built my game with Phaser 3.55.2. I’ve read many threads on here and on Stack Overflow about issues with audio in iOS using Cordova or Capacitor. I noticed most of these are a couple years old at this point. I’ve also researched it with ChatGPT.
Does anyone know a definitive way to get the audio to work with Phaser’s audio system without switching to the Cordova media plugin? For me, sound works everywhere but in my Cordova app for iOS (it works in Safari). I’m using Ionic WebView. With webAudio enabled, the app won’t load any audio files, so I went with HTML5 audio. I’m using mp3’s. Attached is the class I wrote to manage my soundtrack and effects. In my preload, I simply run:
soundManager = new SoundManager(this);
SoundManager.js (4.7 KB)
Below is what I’ve done\tried. I’m wondering:
- Am I missing something really dumb to get it working?
- Do I have to redo the sound system with the media plugin for Cordova?
- Does this simply not work for some reason I missed?
config.xml
<preference name=AllowInlineMediaPlayback value=true />
<preference name="AllowMixedContent" value="true" />
<preference name=MediaTypesRequiringUserActionForPlayback value=none />
<config-file parent="UIBackgroundModes" target="*-Info.plist">
<array>
<string>audio</string>
</array>
</config-file>
JavaScript
audio: {
disableWebAudio: true
}
new ((window).AudioContext || (window).webkitAudioContext)()
this.playButton = this.add.text(98, 138, 'START', this.styles);
this.playButton.setInteractive().on('pointerdown', function(){
that.scene.stop();
**that.sound.unlock();** // I read this is not needed for HTML5 audio.
that.scene.launch('Intermission', {
color:that.characterColor,
world:gameData.get('world'),
character:gameData.get('character'),
mode:(localStorage.getItem('mode') ? localStorage.getItem('mode') : 'Nice')
});
});
});