title: How to play several fragments of mp3 synchronously?
body: <p>It's my second question about JavaFX. I am sorry cause I am not an experienced Java programmer and quite a novice with JavaFX. I don't understand previous answer thoroughly and will read it again and again later. But now I have the next question. I rewrite my program as follows:</p>
  
  <pre><code> import java.io.FileNotFoundException;
   import java.io.IOException;
   import static java.lang.Thread.sleep;
   import java.util.concurrent.TimeUnit;
   import javafx.application.Application;
   import javafx.scene.media.Media;
   import javafx.scene.media.MediaPlayer;
   import javafx.stage.Stage; import javafx.util.Duration;
  
   public class JavaFXMediaPlayer05 extends Application {
  
       public static void main(String[] args) {
           launch(args);
       }
  
       @Override
       public void start(Stage stage) throws FileNotFoundException,IOException, InterruptedException {
           Media media = new Media("file:///D:/1016_00.mp3");
   //Set and play the first fragment of mp3-file
           MediaPlayer mediaPlayer1 = new MediaPlayer(media);
           mediaPlayer1.setStartTime(Duration.millis(1219.0));
           mediaPlayer1.setStopTime(Duration.millis(2728.0));
           mediaPlayer1.play();
           System.out.println("1st fragment played!");
           TimeUnit.SECONDS.sleep(3);
   //Set and play the second fragment
           MediaPlayer mediaPlayer2 = new MediaPlayer(media);
           mediaPlayer2.setStartTime(Duration.millis(3947.0));
           mediaPlayer2.setStopTime(Duration.millis(6629.0));
           mediaPlayer2.play();
           System.out.println("2nd fragment played!");
           TimeUnit.SECONDS.sleep(3);
   //Set and play the third fragment
           MediaPlayer mediaPlayer3 = new MediaPlayer(media);
           mediaPlayer3.setStartTime(Duration.millis(7453.0));
           mediaPlayer3.setStopTime(Duration.millis(10704.0));
           mediaPlayer3.play();
           System.out.println("3rd fragment played!");
   //Just sleep
           System.out.println("pre-sleep");
           TimeUnit.SECONDS.sleep(3);
           System.out.println("after-sleep");
       }
   }
  </code></pre>
  
  <p>And I debug it in NetBeans step-by-step. I get a strange result. I hear the sound not at mediaplayer.play() but only at the end of method start(). All 3 fragments play at once. How do I manage them to play sequentially? Do I have to fire method start() many times - one time for every fragment? Or is there another way?</p>