1 Reply Latest reply on May 11, 2020 11:52 AM by pietblok

    Update build 1.8.0_251-b08 makes MediaPlayer freeze

    pietblok

      Good day,

       

      Last week my JRE got updated to build 1.8.0_251-b08, by the semi automatic update process. Yes, I clicked update now.

       

      To my horror, the one and only javafx application that I have ever written, for my own pleasure and convenience, stopped working after that update. It is an application that heavily uses the javafx.scene.media package.

       

      I tried to figure out how to roll back the update, but that seems impossible. I have only the JRE and not an SDK. I develop and compile with Eclipse.

       

      The problem: as said is with the media package. I created my own fully fledged media player with this package. What happens is the following:

       

      1) A media file is selected

      2) Media, MediaPlayer and MediaView instances are created

      3) The MediaView is incorporated in the scene tree

      4) The player is started

       

      What happened before the update:

      The media is shown playing (the image is moving), the sound is audible and an indicator of the time is displayed. The media player status is shown as "PLAYING". In short: everything works fine and as intended.

       

      After the update however, the image is frozen: I can hear the audio, the time indicator is running and the status is "PLAYING". When stopping the video, everything stops, and when restarting the video restarts at that point, only with a frozen image. In short: my application has become useless.

       

      Has anyone seen this behaviour in the updated JRE? Has anyone succeeded to play a video in the updated JRE without freeze at all? Has anyone a suggestion as what might be wrong here?

       

      Does anyone know of a way to revert to the previous JRE build (I believe this is 1.8.0_241-b07)?

       

      Any help is appreciated,

       

      Piet

        • 1. Re: Update build 1.8.0_251-b08 makes MediaPlayer freeze
          pietblok

          Finally I have found what the problem caused. I build an application from scratch in which I tried to implement everything that I was using in my full blown application. There I found the line that froze the video: one single line in apparently an too early stage where StartTime was set to a Duration.ZERO value. I had added this line because in the abundant use of bindings to control a progressbar and what all, an Exception because of a null value was thrown. In these custom bindings I used mediaPlayer.startTimeProperty().get(). I have changed this to mediaPlayer.getStartTime() (which can give a different result), so that an Exception is prevented. and I can omit the setStartTime(Duration.Zero).

           

          Here an example that shows the problem.

          package jrebug;

           

          import javafx.application.Application;

          import javafx.beans.binding.Bindings;

          import javafx.beans.value.ChangeListener;

          import javafx.beans.value.ObservableValue;

          import javafx.scene.Scene;

          import javafx.scene.input.MouseEvent;

          import javafx.scene.layout.Pane;

          import javafx.scene.media.Media;

          import javafx.scene.media.MediaPlayer;

          import javafx.scene.media.MediaPlayer.Status;

          import javafx.scene.media.MediaView;

          import javafx.stage.FileChooser;

          import javafx.stage.Stage;

          import javafx.util.Duration;

           

          public class EmbeddedMediaPlayer extends Application {

           

              private static final String MEDIA_URL = "http://download.oracle.com/otndocs/products/javafx/oow2010-2.flv";

           

              public static void main(String[] args) {

                  launch(args);

              }

           

              private Media media = null;

           

              private MediaPlayer mediaPlayer = null;

           

              @Override

              public void start(Stage primaryStage) throws Exception {

                  primaryStage.setTitle("Embedded Media Player");

                  String url = getURL();

                  primaryStage.setTitle("Opening " + url);

                  primaryStage.show();

                  media = new Media(url);

                  mediaPlayer = new MediaPlayer(media);

                  mediaPlayer.setAutoPlay(true);

                 

                  /*

                   * The following line causes the video to freeze.

                   *

                   * Remove this line to un-freeze the video

                   */

                  mediaPlayer.setStartTime(Duration.ZERO);

                  /*

                   * End of offending line

                   */

           

                  mediaPlayer.setCycleCount(10000);

           

                  primaryStage.setScene(new Scene(createMediaPane()));

           

                  monitor(mediaPlayer, primaryStage);

              }

           

              private Pane createMediaPane() {

                  Pane mediaPane = new Pane();

                  MediaView mediaView = new MediaView(mediaPlayer);

                  mediaView.setOnMouseClicked((event) -> mouseClicked(event));

                  mediaPane.getChildren().add(mediaView);

                  mediaPane.setStyle("-fx-background-color: black");

           

                  mediaPane.prefWidthProperty().bind(media.widthProperty());

                  mediaPane.prefHeightProperty().bind(media.heightProperty());

           

                  mediaView.fitWidthProperty().bind(mediaPane.widthProperty());

                  mediaView.fitHeightProperty().bind(mediaPane.heightProperty());

           

                  mediaView.xProperty().bind(Bindings.selectDouble(mediaView.parentProperty(), "width").divide(2.0)

                          .subtract(Bindings.min(mediaView.fitWidthProperty(), mediaView.fitHeightProperty()).divide(2)));

                  mediaView.yProperty().bind(Bindings.selectDouble(mediaView.parentProperty(), "height").divide(2.0)

                          .subtract(Bindings.min(mediaView.fitHeightProperty(), mediaView.fitWidthProperty()).divide(2)));

           

                  return mediaPane;

              }

           

              private String getURL() {

                  try {

                      return new FileChooser().showOpenDialog(null).toURI().toURL().toString();

                  } catch (Throwable t) {

                      return MEDIA_URL;

                  }

              }

           

              private void monitor(final MediaPlayer mediaPlayer, Stage primaryStage) {

                  mediaPlayer.statusProperty().addListener(new ChangeListener<Status>() {

           

                      @Override

                      public void changed(ObservableValue<? extends Status> prop, Status oldStatus, Status newStatus) {

                          primaryStage.setTitle("Status changed from " + oldStatus + " to " + newStatus);

                          switch (newStatus) {

                          case READY:

                              primaryStage.sizeToScene();

                              primaryStage.show();

                          default:

                              break;

                          }

                      }

                  });

           

                  mediaPlayer.setOnReady(() -> primaryStage.setTitle("MediaPlayer is ready"));

           

              }

           

              private void mouseClicked(MouseEvent event) {

                  switch (mediaPlayer.getStatus()) {

                  case PLAYING:

                      mediaPlayer.pause();

                      break;

                  case PAUSED:

                      mediaPlayer.play();

                      break;

                  default:

                      break;

                  }

                  event.consume();

              }

           

          }