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

MediaPlayer doesn't update status property when end of media is reached

XMLWordPrintable

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

      If the MediaPlayer reaches the specified number of cycle count, the sound stops playing (like expected) but the status property is not updated. Cause no sound is played anymore I would expect the status to change to stopped.

      Code snippet to demonstrate the behaviour:


      import javafx.embed.swing.JFXPanel;
      import javafx.scene.media.Media;
      import javafx.scene.media.MediaPlayer;

      public class MediaPlayerStatusTest
      {
          public static void main(final String[] args) throws Exception
          {
              new MediaPlayerStatusTest();
          }

          public MediaPlayerStatusTest() throws Exception
          {
              // init
              new JFXPanel();

              String audioSource = getClass().getResource("sound1.wav").toURI().toString();

              MediaPlayer player = new MediaPlayer(new Media(audioSource));
              player.setCycleCount(3);
              player.play();

              // sleep required due to RT-31736
              Thread.sleep(1000);

              long duration = new Double(player.getMedia().getDuration().toMillis()).longValue();
              System.out.println("Duration of the sound: " + duration);
              System.out.println("Status (expected PLAYING): " + player.getStatus());

              // sleep until the player has reached the specified cycle count
              // and stopped playing the sound
              Thread.sleep(duration * 5);

              // sound has terminated. I would expect a changed status
              System.out.println("Status (expected STOPPED): " + player.getStatus());

              // try to play it again
              player.play(); // this has no effect, cause stop has to be called first
          }
      }


      Output:
      Duration of the sound: 489
      Status (expected PLAYING): PLAYING
      Status (expected STOPPED): PLAYING

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

              Created:
              Updated:
              Imported: