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

MediaPlayer doesn't update status property

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 7u25
    • javafx

      Try this:

      import java.io.File;

      import javafx.application.Application;
      import javafx.application.Platform;
      import javafx.scene.media.Media;
      import javafx.scene.media.MediaPlayer;
      import javafx.stage.Stage;

      public class BugReportMain extends Application {

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

          @Override
          public void start(Stage primaryStage) throws Exception {
              final File sourceFile = new File("/media/music/musik/Pop/Abba - Gimme Gimme Gimme.mp3");
              final Media media = new Media(sourceFile.toURI().toURL().toString());
              final MediaPlayer player = new MediaPlayer(media);

              // force the player to do what it's there for
              player.play();
              System.out.println("current status: " + player.getStatus());
              player.stop();
              System.out.println("current status: " + player.getStatus());

              Platform.exit();
          }
      }

      (Let the source file point to any of your mp3 file that is valid).
      At least on my system, the status of the media player is not updated, it always tells me that the status is UNKNOWN.

      If I add a change listener on the status property, the status is not even set to UNKNOWN, instead it stays null:

      import java.io.File;

      import javafx.application.Application;
      import javafx.application.Platform;
      import javafx.beans.value.ChangeListener;
      import javafx.beans.value.ObservableValue;
      import javafx.scene.media.Media;
      import javafx.scene.media.MediaPlayer;
      import javafx.scene.media.MediaPlayer.Status;
      import javafx.stage.Stage;

      public class BugReportMain extends Application {

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

          @Override
          public void start(Stage primaryStage) throws Exception {
              final File sourceFile = new File("/media/music/musik/Pop/Abba - Gimme Gimme Gimme.mp3");
              final Media media = new Media(sourceFile.toURI().toURL().toString());
              final MediaPlayer player = new MediaPlayer(media);
              player.statusProperty().addListener(new ChangeListener<Status>() {

                  @Override
                  public void changed(ObservableValue<? extends Status> observable, Status oldValue, Status newValue) {
                      System.out.println("status changed: " + oldValue + " -> " + newValue);
                  }
              });

              // force the player to do what it's there for
              player.play();
              System.out.println("current status: " + player.getStatus());
              player.stop();
              System.out.println("current status: " + player.getStatus());

              Platform.exit();
          }
      }

      I would expect the media player to react in a different way.

      1. Don't forget to set internal status if there is a change listener registered (IMO, this shouldn't play a role)
      2. On the play / stop / pause calls, update the status property

      Maybe this behaviour influences #RT-31627 or vice versa.

            Unassigned Unassigned
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Imported: