Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8088375

Mediaplayer not looping MP4 file on Mac OSX

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Icon: P3 P3
    • None
    • 8u40, 9
    • javafx
    • Hardware Overview:

      Model Name: MacBook Pro
      Model Identifier: MacBookPro10,1
      Processor Name: Intel Core i7
      Processor Speed: 2,3 GHz

      OS X Yosemite 10.10.2

      Execute the example code on the sample at

      https://www.dropbox.com/s/p900vpmz2qrvooh/test.mp4

      and watch the behaviour and output. The player does not loop at all although it is configured to do so. The status changes look odd too. I am not sure about the semantics of end of media but it is called way before the video ends and when the video ends (and does not loop) no other status change is fired. The same file loops fine in Quicktime on the same machine.

      Tested with 8u40 and 8u60ea

      Sample code:


      import javafx.application.Application;
      import javafx.scene.Scene;
      import javafx.scene.layout.StackPane;
      import javafx.scene.media.Media;
      import javafx.scene.media.MediaPlayer;
      import javafx.scene.media.MediaView;
      import javafx.scene.text.Text;
      import javafx.stage.Stage;

      import java.util.List;

      /**
       * Simple Media Player Example
       */
      public class MediaPlayerExample extends Application {

          @Override
          public void start(Stage stage) throws Exception {
              StackPane pane = new StackPane();

              final List<String> args = getParameters().getRaw();

              if(args.isEmpty()){
                  throw new IllegalStateException("no file specified");
              }

              final String file = args.get(0);

              System.out.println("Playing " + file);

              final Media media = new Media(file);

              final MediaPlayer player = new MediaPlayer(media);
              player.setOnEndOfMedia(() -> System.out.println("End of media"));
              player.setCycleCount(MediaPlayer.INDEFINITE);

              MediaView mediaView = new MediaView(player);
              final Text text = new Text("Click to play");

              pane.setOnMouseClicked((e) -> {
                  if (player.getStatus() != MediaPlayer.Status.PLAYING) {
                      System.out.println("Playing");
                      pane.getChildren().remove(text);
                      player.play();
                  } else if (player.getStatus() == MediaPlayer.Status.PLAYING) {
                      System.out.println("Pausing");
                      pane.getChildren().add(text);
                      player.pause();
                  }
              });

              pane.getChildren().add(mediaView);
              pane.getChildren().add(text);

              final Scene scene = new Scene(pane);
              stage.setScene(scene);
              stage.setTitle(getClass().getSimpleName());
              player.setOnReady(() -> {
                  System.out.println("Player ready");
                  // metadata only available now
                  mediaView.setFitWidth(media.getWidth());
                  mediaView.setFitHeight(media.getHeight());
                  stage.sizeToScene();
                  stage.show();
              });
              player.statusProperty().addListener((e, o, n)->{
                  System.out.println("Status change from " + o + " to " + n);
              });
          }

          public static void main(String[] args) {
              launch(args);
          }
      }


       

            almatvee Alexander Matveev
            rkruegerjfx Robert Krueger (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: