hi everybody,
i needed to play mp3 audio in my AudioPlayer project
i found jlayer is the easiest way to play mp3 audio,it plays well but can't stop playing
my GUI stops responding until the audio is finished!

any help please

this is the code of the playing button
-chooser is a jfilechooser object

file=chooser.getSelectedFile();
        FileInputStream f=new FileInputStream(file);
        ap=new AdvancedPlayer(f);
        ap=new AdvancedPlayer(f);
        ap.play();

and in the stop button

ap.stop()

hi everybody,
i needed to play mp3 audio in my AudioPlayer project
i found jlayer is the easiest way to play mp3 audio,it plays well but can't stop playing
my GUI stops responding until the audio is finished!

any help please

this is the code of the playing button
-chooser is a jfilechooser object

file=chooser.getSelectedFile();
        FileInputStream f=new FileInputStream(file);
        ap=new AdvancedPlayer(f);
        ap=new AdvancedPlayer(f);
        ap.play();

and in the stop button

ap.stop()

I think the reason is that the player is taking up your entire thread, and therefore your thread of your gui will have to wait until its played finished. Create a new Runnable and play it using that, this then means your music will be playing on a separate thread and therefore not blocking your gui thread and the gui will continue as normal. see here:http://www.go4expert.com/forums/showthread.php?t=4202 You'd then have to make a variable like StopPlaying in the new class that implements the runnable, and when the user presses stop it changes the value of the boolean to true:

while(stopPlaying==false) {
}
ap.stop();//code will only reach here when stopPlaying is true...

Edited 4 Years Ago by DavidKroukamp: n/a

I think the reason is that the player is taking up your entire thread, and therefore your thread of your gui will have to wait until its played finished. Create a new Runnable and play it using that, this then means your music will be playing on a separate thread and therefore not blocking your gui thread and the gui will continue as normal. see here:http://www.go4expert.com/forums/showthread.php?t=4202 You'd then have to make a variable like StopPlaying in the new class that implements the runnable, and when the user presses stop it changes the value of the boolean to true:

while(stopPlaying==false) {
}
ap.stop();//code will only reach here when stopPlaying is true...

this also might be useful:http://www.informit.com/guides/content.aspx?g=java&seqNum=290.. I couldn't find the exact way to stop it playing but i reckon you're right

If you start the player playing in its own thread, as correctly advised by cOrRuPtG3n3t!x, then I see no reason why you can't just call ap.stop() directly from the Swing thread (eg in a button's action listener) - no need for flag variables etc. (If you can't call stop() from a thread other than the one where play() was called, then it has no possible use!)

Edited 4 Years Ago by JamesCherrill: n/a

Comments
True, Old wise man :P
This question has already been answered. Start a new discussion instead.