Cordova / iOS sound issue

I have some users reporting intermittent distorted/crackling sound on iOS. It seems related to a bug I have read in other forums:

The above webkit fix suggests that this could be a fix: ‘if on startup we create an AudioContext, immediately call close() on it, throw it away, then create a new AudioContext which we use for the rest of the app, it appears to work correctly’.

How would this be done in Phaser?

You could try

(new AudioContext()).close();

new Phaser.Game(…);

Thanks samme. That didn’t work, but I will continue to experiment based on your suggestion.

Technically it’s

(new webkitAudioContext()).close()

I guess.

That bug is really old, so I’d be surprised if it’s still relevant. I have found, though, that there are some sample rates that iOS just cannot handle - and that it struggles if you’re playing audio with a mixture of sample rates. I’d go through and double-check all of the audio files use the same format, bit rate, etc and it’s a tried and tested one.

I think you are right Rich. My video and audio are very mixed: 48 kHz, 44.1 kHz, 32 kHz, etc.

Know a good batch converter? I have thousands of files. gulp.

Adobe Audition can batch handle this, but I’m sure there are others too.

Before doing so, I would build a test app, where you know for a fact all the audio is matching, and get it tested out - if it resolves the issue, then you could spend time batching the rest of the files.

ffmpeg to the rescue! Will try conservatively and with testing, of course. Thanks Rich.

Converting all audio files to the same bit rate seemed to have fixed this issue.

1 Like

Hi which formats are you using for your sound assets?

MP3 exclusively

You can add .ogg type too and load with mp3 at same time. I’m always loading both and never had problems like that.
Phaser will load only one of them based on OS and browser type.

This issue is still problematic, but looks like it’s caused by using WKWebView with Cordova:

More information around ‘crackling’ issue:

A temporary solution I found for audio cutting out, especially in iOS 13:

  1. Use your own audio context:

var audioContext = new ((window).AudioContext || (window).webkitAudioContext)();

  1. Pass this into the game config as a custom audio context:

audio: {
context: audioContext

  1. Listen for the ‘focus’ window event, which will allow you to then resume() the audio context after waiting a little bit:

window.addEventListener(“focus”, function(event)
}, 1000);

1 Like

For Cordova, I prefer to use cordova-plugin-media, which does not require to preload the sound and able to play smoothly.