Sign in to follow this  

[java] stoping playback of a mp3 javazooms JLayer

Recommended Posts

I'm having some serious problems trying to figure out javazoom's mp3 library.
At first I created a instance of the AdvancedPlayer class, and found it caused my other code to not run untill the mp3 was finished playing. So I figured to dump it into it's own thread class. But I for the life of me can't figure out how I can get the mp3 to stop playing for stop/pausing. In all my testing all I've been able to deduce is that after calling in run(), run does not continue to execute past it. Could someone help me understand what I'm doing wrong?

Here is some of my code. Let me know if you need anything else.
public class MusicPlayer implements Runnable{

final Thread musicThread = new Thread(this);

// mp3 music player
AdvancedPlayer mp3Player;
PlaybackListener mp3Listener;

// to help direct mp3 playback
boolean musicPaused = false;
boolean musicStoped = false;
boolean musicLoops = true;
int pausePos;

public MusicPlayer()
// setup our mp3 playback events
mp3Listener = new PlaybackListener(){
public void playbackStarted(PlaybackEvent evt) {
// todo

public void playbackStoped(PlaybackEvent evt) {
// todo


public void loadMusic(String file){
mp3Player = new AdvancedPlayer(new FileInputStream(file));
} catch (JavaLayerException ex){
JOptionPane.showMessageDialog(null, "Player filed to initialize. Music will not play!",
"warrning!", JOptionPane.ERROR_MESSAGE);

} catch (FileNotFoundException ex) {
JOptionPane.showMessageDialog(null, "Music file not found. Music will not play!: " + ex,
"warrning!", JOptionPane.ERROR_MESSAGE);


public void playMusic(){

public void run() {
if (mp3Player != null)
try {;
//code execution never reaches past here!

} catch (JavaLayerException ex){
JOptionPane.showMessageDialog(null, "Music failed to play!: " + ex,
"warrning!", JOptionPane.ERROR_MESSAGE);


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this