Neil
Neil

Reputation: 6039

JavaFx : Playing list of media files with pause in between

I am trying to play a list of mp3 files in JavaFx and need to pause for few seconds in between each file.This question may be subjective but I am unable to find any technique to get handle of another JavaFx MediaPlayer object at the end of currently playing mediaPlayer, which is being played inside a runnable object.

Any code sample/Algorithm will be a great help.

Upvotes: 1

Views: 1917

Answers (2)

Stephan
Stephan

Reputation: 43083

Turn @SoulMan's comment into answer:


Thanks I used the following code:

PauseTransition pt = new PauseTransition(Duration.millis(2000));
pt.play();
pt.setOnFinished(
    new EventHandler<ActionEvent>() {
      @Override
      public void handle(ActionEvent event) {
         if (mediaPlayer3 != null) {
             mediaPlayer3.play();
         }
      }
});

Upvotes: 1

jewelsea
jewelsea

Reputation: 159576

Create a list of mediaPlayers, iterate through the list and for each mediaPlayer:

  1. Call mediaPlayer.setonEndofMedia.
  2. In your end of media Runnable create a PauseTransition for the duration you want to pause.
  3. Supply a setOnFinished event handler for the pause transition which starts the next MediaPlayer in the list.

Upvotes: 2

Related Questions