Why following cod开发者_如何学Ce doesn't work with me? :S
AudioPlayer.player.start(file1);
while(AudioPlayer.player.isAlive()) {}
AudioPlayer.player.start(file2);
I want to play my files one-by-one :S
I assume you are referring to sun.audio.AudioPlayer
. If so, you should be aware that the sun.*
classes are for use by the JRE only; you should look in the javax.sound.*
packages instead. (See also the Java tutorial on sound).
Having said that, the isAlive()
method is on the Thread
class, and since the audioplayer thread sticks around, this method never returns false.
I would try to detect the end of the song by looking to see whether the underlying InputStream
has been closed (e.g. by overriding the close()
method). Alternatively, you could make an InputStream
which sequences the two input streams you are trying to play.
精彩评论