• Advertisement
Sign in to follow this  

[java] stoping playback of a mp3 javazooms JLayer

This topic is 2474 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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 mp3Player.play() 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){
try{
mp3Player = new AdvancedPlayer(new FileInputStream(file));
//mp3Player.setPlayBackListener(mp3Listener);
} 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(){
musicThread.start();
}

public void run() {
if (mp3Player != null)
{
try {
mp3Player.play();
//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
Advertisement
Sign in to follow this  

  • Advertisement