How to Stop Current Playing Song When using one thread with JLayer?
- by mcnemesis
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?