SwiftySound icon indicating copy to clipboard operation
SwiftySound copied to clipboard

After the 5th time playing a sound doesn't start from 0:00.

Open VotusX opened this issue 4 years ago • 3 comments

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

VotusX avatar Jan 24 '21 12:01 VotusX

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.

SuperWomble avatar Apr 09 '21 01:04 SuperWomble

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.

six8 avatar May 04 '21 22:05 six8

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.

adamcichy avatar Nov 04 '21 21:11 adamcichy