Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
VotusX opened this issue Jan 24, 2021 · 3 comments
Open

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

VotusX opened this issue Jan 24, 2021 · 3 comments

Comments

@VotusX
Copy link

VotusX commented Jan 24, 2021

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

@SuperWomble
Copy link

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.

@six8
Copy link

six8 commented May 4, 2021

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.

@adamcichy
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants