# Cordova / iOS sound issue

**URL:** <https://phaser.discourse.group/t/cordova-ios-sound-issue/3811>\
**Category:** Phaser 3\
**Created:** [September 26, 2019, 12:24pm UTC](https://phaser.discourse.group/t/cordova-ios-sound-issue/3811 "2019-09-26T12:24:08Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![paul](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/paul/32/22_2.png) [@paul](https://phaser.discourse.group/u/paul)\
**Post date:** [September 26, 2019, 12:24pm UTC](https://phaser.discourse.group/t/cordova-ios-sound-issue/3811/1 "2019-09-26T12:24:08Z")

</div>

I have some users reporting intermittent distorted/crackling sound on iOS. It seems related to a bug I have read in other forums: [https://bugs.webkit.org/show\_bug.cgi?id=154538](https://bugs.webkit.org/show_bug.cgi?id=154538)

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?

---

<div class="post-metadata">

**Author:** ![samme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/samme/32/5275_2.png) [@samme](https://phaser.discourse.group/u/samme)\
**Post date:** [September 26, 2019, 3:17pm UTC](https://phaser.discourse.group/t/cordova-ios-sound-issue/3811/2 "2019-09-26T15:17:46Z")

</div>

You could try

```javascript
(new AudioContext()).close();

new Phaser.Game(…);
```

---

<div class="post-metadata">

**Author:** ![paul](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/paul/32/22_2.png) [@paul](https://phaser.discourse.group/u/paul)\
**Post date:** [September 26, 2019, 7:15pm UTC](https://phaser.discourse.group/t/cordova-ios-sound-issue/3811/3 "2019-09-26T19:15:38Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![samme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/samme/32/5275_2.png) [@samme](https://phaser.discourse.group/u/samme)\
**Post date:** [September 26, 2019, 7:23pm UTC](https://phaser.discourse.group/t/cordova-ios-sound-issue/3811/4 "2019-09-26T19:23:39Z")

</div>

Technically it’s

```javascript
(new webkitAudioContext()).close()

```

I guess.

---

<div class="post-metadata">

**Author:** ![rich](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/rich/32/4_2.png) [@rich](https://phaser.discourse.group/u/rich)\
**Post date:** [September 26, 2019, 9:23pm UTC](https://phaser.discourse.group/t/cordova-ios-sound-issue/3811/5 "2019-09-26T21:23:32Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![paul](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/paul/32/22_2.png) [@paul](https://phaser.discourse.group/u/paul)\
**Post date:** [September 26, 2019, 9:35pm UTC](https://phaser.discourse.group/t/cordova-ios-sound-issue/3811/6 "2019-09-26T21:35:28Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![rich](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/rich/32/4_2.png) [@rich](https://phaser.discourse.group/u/rich)\
**Post date:** [September 26, 2019, 10:17pm UTC](https://phaser.discourse.group/t/cordova-ios-sound-issue/3811/7 "2019-09-26T22:17:53Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![paul](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/paul/32/22_2.png) [@paul](https://phaser.discourse.group/u/paul)\
**Post date:** [September 26, 2019, 11:16pm UTC](https://phaser.discourse.group/t/cordova-ios-sound-issue/3811/8 "2019-09-26T23:16:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![paul](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/paul/32/22_2.png) [@paul](https://phaser.discourse.group/u/paul)\
**Post date:** [October 10, 2019, 5:59pm UTC](https://phaser.discourse.group/t/cordova-ios-sound-issue/3811/9 "2019-10-10T17:59:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![RollinSafary](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/rollinsafary/32/2159_2.png) [@RollinSafary](https://phaser.discourse.group/u/RollinSafary)\
**Post date:** [October 11, 2019, 9:34am UTC](https://phaser.discourse.group/t/cordova-ios-sound-issue/3811/10 "2019-10-11T09:34:10Z")

</div>

Hi which formats are you using for your sound assets?

---

<div class="post-metadata">

**Author:** ![paul](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/paul/32/22_2.png) [@paul](https://phaser.discourse.group/u/paul)\
**Post date:** [October 11, 2019, 12:48pm UTC](https://phaser.discourse.group/t/cordova-ios-sound-issue/3811/11 "2019-10-11T12:48:02Z")

</div>

MP3 exclusively

---

<div class="post-metadata">

**Author:** ![RollinSafary](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/rollinsafary/32/2159_2.png) [@RollinSafary](https://phaser.discourse.group/u/RollinSafary)\
**Post date:** [October 11, 2019, 3:10pm UTC](https://phaser.discourse.group/t/cordova-ios-sound-issue/3811/12 "2019-10-11T15:10:30Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![paul](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/paul/32/22_2.png) [@paul](https://phaser.discourse.group/u/paul)\
**Post date:** [November 9, 2019, 1:26pm UTC](https://phaser.discourse.group/t/cordova-ios-sound-issue/3811/13 "2019-11-09T13:26:36Z")

</div>

This issue is still problematic, but looks like it’s caused by using WKWebView with Cordova: [https://forums.developer.apple.com/thread/121822](https://forums.developer.apple.com/thread/121822)

---

<div class="post-metadata">

**Author:** ![paul](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/paul/32/22_2.png) [@paul](https://phaser.discourse.group/u/paul)\
**Post date:** [November 9, 2019, 2:20pm UTC](https://phaser.discourse.group/t/cordova-ios-sound-issue/3811/14 "2019-11-09T14:20:17Z")

</div>

More information around ‘crackling’ issue: [https://stackoverflow.com/questions/54982847/crackles-and-noises-when-playing-ios-web-audio-with-simple-graph](https://stackoverflow.com/questions/54982847/crackles-and-noises-when-playing-ios-web-audio-with-simple-graph)

---

<div class="post-metadata">

**Author:** ![paul](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/paul/32/22_2.png) [@paul](https://phaser.discourse.group/u/paul)\
**Post date:** [November 21, 2019, 2:48am UTC](https://phaser.discourse.group/t/cordova-ios-sound-issue/3811/15 "2019-11-21T02:48:16Z")

</div>

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)  
{  
setTimeout(function(){  
console.log(‘resuming…’)  
audioContext.resume();  
}, 1000);  
},  
false);

---

<div class="post-metadata">

**Author:** ![NickChowHK](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/nickchowhk/32/2377_2.png) [@NickChowHK](https://phaser.discourse.group/u/NickChowHK)\
**Post date:** [September 15, 2020, 8:46am UTC](https://phaser.discourse.group/t/cordova-ios-sound-issue/3811/16 "2020-09-15T08:46:06Z")

</div>

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