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

MediaPlayer does not display an mp4 if there no speakers connected to the PC's

    XMLWordPrintable

    Details

    • Subcomponent:
    • CPU:
      x86_64
    • OS:
      windows_10

      Description

      ADDITIONAL SYSTEM INFORMATION :
      Running Java 14.0.2, JavaFX 16ea+1, NetBeans using Maven, Windows 10.

      A DESCRIPTION OF THE PROBLEM :
      I have used a sample for years that plays a video. For the first time this year I am using a PC that has sound going thru a USB connection. That is fine and the video plays. But if I remove the USB my Win PC tells me there are no speakers which is correct. Now, when I run the program, its only a stage, scene and media player with a hardcoded mp4 file location, the window opens and nothing but a white background appears. No log messages, no exceptions.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Remove all speakers on any program that plays an mp4 with the Media Player. Beware, laptops with built in speakers will never exhibit this problem. Desktop boxes that default to an internal speaker will also never exhibit this problem.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Play a video
      ACTUAL -
      Does not play video

      ---------- BEGIN SOURCE ----------
      import java.net.URISyntaxException;
      import javafx.application.Application;
      import static javafx.application.Application.launch;
      import javafx.scene.Group;
      import javafx.scene.Scene;
      import javafx.scene.media.Media;
      import javafx.scene.media.MediaPlayer;
      import javafx.scene.media.MediaView;
      import javafx.stage.Stage;

      /**
       * Example of playing a video
       *
       * @author Ken
       */
      public class MainApp extends Application {

          /**
           * Start the JavaFX application
           *
           * @param primaryStage
           * @throws java.net.URISyntaxException
           */
          @Override
          public void start(Stage primaryStage) throws URISyntaxException {

              primaryStage.setTitle("San Francisco Street Car");

              // Video is 16 x 9 so I calculated the correct ratio
              int width = 800;
              int height = 450;
              // replace with any video that has sound
              String path = "/video/SFCableCar.MP4";

              Group root = new Group();
              root.getChildren().add(createMediaView(path, width, height));
              primaryStage.setScene(new Scene(root, width, height));
              primaryStage.show();
          }

          /**
           * Create a MediaView that scales the media
           *
           * @param width
           * @param height
           * @return
           * @throws URISyntaxException
           */
          private MediaView createMediaView(String path, int width, int height) throws URISyntaxException {
              Media media = new Media(getClass().getResource(path).toURI().toString());
              MediaPlayer mediaPlayer = new MediaPlayer(media);
              mediaPlayer.setAutoPlay(true);
              MediaView mediaView = new MediaView(mediaPlayer);
              mediaView.setFitHeight(width);
              mediaView.setFitWidth(width);
              return mediaView;
          }

          /**
           *
           * @param args the command line arguments
           */
          public static void main(String[] args) {
              launch(args);
          }
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      There is no workaround.

      FREQUENCY : always


        Attachments

          Activity

            People

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

              Dates

              Created:
              Updated: