I'm trying to play some simple interface sound effects, and the method I found online does not work. I don't get any errors but the sounds just don't play. My phone is not on silent mode, the volume is all the way up.
if let soundUrl = Bundle.main.url(forResource: filename, withExtension: ext) {
var soundId: SystemSoundID = 0
AudioServicesCreateSystemSoundID(soundUrl as CFURL, &soundId)
AudioServicesPlaySystemSoundWithCompletion(soundId, {
AudioServicesDisposeSystemSoundID(soundId);
});
}
I also tried adding this but it did not help:
AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback)
Any ideas?