Swag Swagger
Swag Swagger

Reputation: 21

How to loop an MP3 file in javafx?

I am trying to figure out how to loop an MP3 using eclipse, what am I doing wrong?

mediaPlayer2.play();{
    mediaPlayer2.setOnEndOfMedia(new Runnable() {
        public void run() {
            mediaPlayer2.seek(Duration.ZERO);
        }
    });
    mediaPlayer2.play();  
}

This should be the code, correct?

Upvotes: 1

Views: 3674

Answers (1)

James_D
James_D

Reputation: 209705

The second call to play() in your code is not in the run() method of the endOfMedia handler, so it won't get called when the media finishes.

But this is not the way to repeat a media player indefinitely anyway. Just do

mediaPlayer2.setCycleCount(MediaPlayer.INDEFINITE);
mediaPlayer2.play();

Upvotes: 2

Related Questions