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

After pausing a MediaPlayer, then continuing to play, the video freezes

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Incomplete
    • Icon: P3 P3
    • None
    • 8u101
    • javafx
    • x86
    • other

      FULL PRODUCT VERSION :
      java version "1.8.0_101"
      Java(TM) SE Runtime Environment (build 1.8.0_101-b13)
      Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 10.0.14393]

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      This version of Windows is running as a virtual machine in VMWare fusion on Mac OS X El Capitan

      A DESCRIPTION OF THE PROBLEM :
      When I play a video using Media/MediaPlayer/MediaView, then pause the video, then continue playing, the video freezes.

      Since this was happening in a VM, I took the JAR for the app and ran it directly on my Mac (no VM) on the exact same version of Java and still get the same result.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Start playing a video in a MediaPlayer. Call the pause() method. Call the play() method. Video restarts for less than a second then freezes every time.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The video should continue playing until pause() is called again or the end of the video is reached.
      ACTUAL -
      Video freezes

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      // mediaView defined in FXML

      package videoplayer;

      import java.net.URL;
      import javafx.application.Platform;
      import javafx.beans.binding.Bindings;
      import javafx.beans.property.DoubleProperty;
      import javafx.event.ActionEvent;
      import javafx.fxml.FXML;
      import javafx.scene.control.Button;
      import javafx.scene.media.Media;
      import javafx.scene.media.MediaPlayer;
      import javafx.scene.media.MediaView;
      import org.controlsfx.dialog.ExceptionDialog;

      public class VideoPlayerController
      {
         @FXML private MediaView mediaView;
         @FXML private Button playPauseButton;
         private MediaPlayer mediaPlayer;
         private boolean playing = false;
            
         public void initialize()
         {
            // get URL of the video file
            URL url = VideoPlayerController.class.getResource("sts117.mp4");
            
            // create a Media object for the specified URL
            Media media = new Media(url.toExternalForm());
            
            // create a MediaPlayer to control Media playback
            mediaPlayer = new MediaPlayer(media);
            
            // specify which MediaPlayer to display in the MediaView
            mediaView.setMediaPlayer(mediaPlayer);

            // set handler to be called when the video completes playing
            mediaPlayer.setOnEndOfMedia(() -> {
               playing = false;
               playPauseButton.setText("Play");
            });

            // set handler that displays an ExceptionDialog if an error occurs
            mediaPlayer.setOnError(() -> {
               ExceptionDialog dialog =
                  new ExceptionDialog(mediaPlayer.getError());
               Platform.runLater(() -> dialog.showAndWait());
            });
            
            // bind the MediaView's width/height to the scene's width/height
            DoubleProperty width = mediaView.fitWidthProperty();
            DoubleProperty height = mediaView.fitHeightProperty();
            width.bind(Bindings.selectDouble(
               mediaView.sceneProperty(), "width"));
            height.bind(Bindings.selectDouble(
               mediaView.sceneProperty(), "height"));
         }
         
         // toggle media playback and the text on the playPauseButton
         @FXML
         private void playPauseButtonPressed(ActionEvent e)
         {
            playing = !playing;

            if (playing)
            {
               playPauseButton.setText("Pause");
               mediaPlayer.play();
            }
            else
            {
               playPauseButton.setText("Play");
               mediaPlayer.pause();
            }
         }
      }

      ---------- END SOURCE ----------

            almatvee Alexander Matveev
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: