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

[macOS, Linux] Instantiating MediaPlayer causes CPU usage to be over 100%

    Details

    • Subcomponent:
    • Introduced In Version:
      9
    • CPU:
      x86_64
    • OS:
      os_x

      Description

      FULL PRODUCT VERSION :
      java version "9.0.4"
      Java(TM) SE Runtime Environment (build 9.0.4+11)
      Java HotSpot(TM) 64-Bit Server VM (build 9.0.4+11, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      macOS High Sierra 10.13.3

      A DESCRIPTION OF THE PROBLEM :
      In Java 9 and later, when you instantiate MediaPlayer, CPU usage exceeds 100%. It occupies one core of multicore. This problem occurs regardless of the playing state of the media.

      This has a fatal impact by exerting a high load on the entire system to the same extent as creating an infinite loop. Therefore, it is practically impossible to use MediaPlayer.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1) Rewrite the source code media file location for your test.
      2) Launch the test application
      3) Press play button

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      It has the same level of CPU usage as running in Java 8.
      ACTUAL -
      The CPU usage rate continues to exceed 100%.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javafx.application.Application;
      import javafx.scene.Scene;
      import javafx.scene.control.ToggleButton;
      import javafx.scene.layout.BorderPane;
      import javafx.scene.media.Media;
      import javafx.scene.media.MediaPlayer;
      import javafx.scene.media.MediaPlayer.Status;
      import javafx.stage.Stage;

      public class MediaPlayerCPUUsageTest extends Application{
      private MediaPlayer player;

      @Override
      public void start(Stage primaryStage) throws Exception {
      Media media = new Media("file://your.mp3");
      ToggleButton playOrStop = new ToggleButton("PLAY");
      playOrStop.selectedProperty().addListener((ob, oldValue, newValue)->{
      if(newValue.booleanValue()) {
      if(player==null) {
      // Lazy load
      player = new MediaPlayer(media);
      player.setCycleCount(MediaPlayer.INDEFINITE);
      player.statusProperty().addListener((ob2, oldValue2, newValue2)->{
      playOrStop.setText( newValue2==Status.PLAYING?"STOP":"PLAY");
      });
      }
      player.play();
      }else {
      player.stop();
      }
      });

      BorderPane root = new BorderPane(playOrStop);
      Scene scene = new Scene(root, 200, 200);
      primaryStage.setScene(scene);
      primaryStage.show();

      }

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

      }
      ---------- END SOURCE ----------

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                almatvee Alexander Matveev
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                6 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: