android-audio-bypass icon indicating copy to clipboard operation
android-audio-bypass copied to clipboard

Play On Awake doesn't always work

Open fadden opened this issue 10 years ago • 0 comments

I think there's a race here: the play-on-awake feature calls Play() right after RegisterSoundFile(), but SoundPool loads the sound file asynchronously. So there's no guarantee that the sound is ready to play at the point where Play() is called.

The plugin needs to have a SoundPool OnLoadCompleteListener. It could provide a WaitUntilLoaded(soundId, timeout) method, allowing AndroidAudioBypass.Start() to register the sound file, wait until it's loaded, and play it. This has the disadvantage of stalling the game engine while sounds load.

A more sophisticated scheme would have a coroutine that watched for load completion and played the sound when ready.

fadden avatar Nov 05 '15 18:11 fadden