Is it possible to play a sound?

Is it actually possible to play a sound on iOS


playSoundFileNamed() causes memory leaks

SKAudioNode() crashes when you leave the app and return, and you can't play sounds simultaneously

AVAudioPlayer causes lag, and you can't play sounds simultaneously


Is it even possible?

Replies

Regarding your points:

> [SKAction] playSoundFileNamed() causes memory leaks

It's been a long time since I've heard a report of this old issue. I can't reproduce the leak in iOS 10.3 or 11. Which OS are you experiencing this on?

> SKAudioNode() crashes when you leave the app and return, and you can't play sounds simultaneously


I'm not familiar with this problem, is there a bug report ID or forums thread that you can reference? If neither and it's reproducible in the latest iOS 11 (currently, beta 3) then file a bug report here and we'll take a look.


> AVAudioPlayer causes lag, and you can't play sounds simultaneously


You can play sounds simultaneously if they are in an uncompressed format (e.g., .wav). One compressed source is allowed for background music (e.g., .mp3), and you can layer multiple uncompressed simultaneous sound effects with AVAudioPlayer. I have no knowledge of its "lag". Do you mean that AVAudioPlayer is laggy as compared to using SKAction playSoundFileNamed or SKAudioNode?


I'll need more information about issues #1 and #2 however before recommending that you use AVAudioPlayer directly. The SpriteKit helper functions do much of the work for you so that game developers can focus on gameplay and graphics and not raw Audio/Video Foundation code.