In my program: I play an audio... I want that when it ends, then the next command be executed..
if I use Thread.sleap
, will the sound keep playing
is there an alternative to Thread.sleep
?
Thread.sleep(5000);
System.out.println("Song is over");
If you are playing the audio on the current thread, Thread.sleep(5000)
will stop the audio. Note that sleep()
is a static method and you call it on the current thread. So if your audio is playing on another Thread t
, then calling t.sleep(5000)
from another thread will not stop the t
thread. Instead it will sleep the current thread from which you are making the call. Hope this helps.
Not sure what you mean by alternative to Thread.sleep()
. Thread.yield()
?
Have you tried anything??
Unless you are playing the audio in a separate thread, the next command should be executed once that the audio clip is played. The code snippet you gave us is pretty limited for us to provide you with a complete answer that suits your case.
精彩评论