Thanks for being a part of WWDC25!

How did we do? We’d love to know your thoughts on this year’s conference. Take the survey here

App Randomly Crashes During Continuous Sound Playback Using AVAudioPlayer

Environment→ ・Device: iPad 10th generation ・OS:**iOS18.3.2

We're using AVAudioPlayer to play a sound when a button is tapped. In our use case, this button can be tapped very frequently — roughly every 0.1 to 0.2 seconds. Each tap triggers the following function:

var audioPlayer: AVAudioPlayer?

func soundPlay(resource: String, type: String){ 
        guard let path = Bundle.main.path(forResource: resource, ofType: type) else { 
            return 
        } 
        do { 
            audioPlayer = try AVAudioPlayer(contentsOf: URL(fileURLWithPath: path)) 
            audioPlayer!.delegate = self 
            try audioSession.setCategory(.playback) 
        } catch { 
            return 
        } 
        self.audioPlayer!.play() 
    } 

The issue is that under high-frequency tapping (especially around 0.1–0.15s intervals), the app occasionally crashes. The crash does not occur every time, but it happens randomly — sometimes within 30 seconds, within 1 minute, or even 3 minutes of continuous tapping.

Interestingly, adding a delay of 0.2 seconds between button taps seems to prevent the crash entirely. Delays shorter than 0.2 seconds (e.g.,0.15s,0.18s) still result in occasional crashes.

My questions are:

**Is this expected behavior from AVAudioPlayer or AVAudioSession?

Could this be a known issue or a limitation in AVFoundation?

Is there any documentation or guidance on handling frequent sound playback safely?**

Any insights or recommendations on how to handle rapid, repeated audio playback more reliably would be appreciated.

App Randomly Crashes During Continuous Sound Playback Using AVAudioPlayer
 
 
Q