How to Stop Current Playing Song When using one thread with JLayer?
Posted
by
mcnemesis
on Stack Overflow
See other posts from Stack Overflow
or by mcnemesis
Published on 2011-01-10T11:43:59Z
Indexed on
2011/01/10
11:53 UTC
Read the original article
Hit count: 254
I recently used a solution to the one-thread-at-a-time problem whe using Jlayer to play mp3 songs in Java. But this solution by Kaleb Brasee didn't hint at how you could stop the player, i.e how could one then call player.close()?
Kaleb's code was:
Executor executor = Executors.newSingleThreadExecutor();
executor.execute(new Runnable() { public void run() {
/* do something */
} });
and this is the code I put in run()
if(player != null) player.close();
try{
player = new Player(new FileInputStream(musicD.getPath()));
player.play();
}catch(Exception e){}
The problem is that much as this solves the problem of keeping the gui active while the music plays (in only one other thread -- what i'd wanted), I can't start playing another song :-(
What could I do?
© Stack Overflow or respective owner