Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+12 votes

SoundPool does not seem to have a way to check if a sound is finished playing which is a problem if you want to wait for one sound to finish before you play another sound. The only way I could think of to handle this is to use Thread.sleep() with the length of the sound being the sleep duration. Is there a better way to do this?

asked in CSC490_Spring2019 by (1 point)

1 Answer

+8 votes
 
Best answer

Not sure... but here are a few thoughts:

If you are doing a Thread.sleep() in between sound playing, make sure that it's happening on a different thread than the main UI thread, since you don't want the UI to freeze up while it's waiting.

Or, (better?), you may want to schedule something to run at a point of time in the future (e.g. more like event-based programming, where an event will be created in the future that triggers some code.)

See some of the examples here, including the 2nd answer using the Handler.postDelayed method, which is Android-specific: https://stackoverflow.com/questions/6205210/is-this-how-to-schedule-a-java-method-to-run-1-second-later

answered by (2k points)
selected by
...