SwiftySound
SwiftySound copied to clipboard
After the 5th time playing a sound doesn't start from 0:00.
Hello,
I was running into the issue that after I play a sound for the fifth time by clicking a button using the Sound.play(file: "X.mp3") method, it doesn't start from it's very beginning and just seems to play at a random point.
Best regards
Looking at the code, there's a weird design issue where 5 instances of AVAudioPlayer are created for every sound. Despite the code comments, I'm not really sure why this is done.
5 instances are queued up so you can quickly play the same sound up to 5 times simultaneous. For example, a bullet sound from a machine gun.
You can switch to just one player per sound like this:
Sound.playersPerSound = 1
This way you will always use the same instance of AVAudioPlayer
for each sound.