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

OpenJDK 8 cannot play MP3 files

XMLWordPrintable

    • x86_64
    • linux_ubuntu

      FULL PRODUCT VERSION :
      $ java -version
      openjdk version "1.8.0_151"
      OpenJDK Runtime Environment (build 1.8.0_151-8u151-b12-0ubuntu0.16.04.2-b12)
      OpenJDK 64-Bit Server VM (build 25.151-b12, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Ubuntu 16.04
      $ uname -a
      Linux EnvyD 4.4.0-98-generic #121-Ubuntu SMP Tue Oct 10 14:24:03 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

      A DESCRIPTION OF THE PROBLEM :
      I'm trying to play audio files via

      new MediaPlayer(new Media(uri)).play()

      This works with WAV files, but does not work with MP3 files. It also works with the 1 AIFF file I had on hand, and did not work with the 1 FLV file I had.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      On Ubuntu 16.04 (64-bit), with OpenJDK 8 installed, find an MP3 file and a WAV file. A freely-available pair is at http://soundbible.com/1746-Ship-Bell.html.

      Run the code I included in the Source Code section of this bug report. Before you do, change the 2 paths in the code to point to your audio files.

      When you run the code, you will get the error I pasted in the Actual Result section, and no sound will play, which is the bug I'm reporting.

      Now, toggle the comments in the code so it tries to run the WAV file instead of the MP3. Then run the code. You should not see an error, and should hear a bell sound (or whatever sound is in your WAV file.)

      Note: if you try to play a long file, you may hear the audio truncated after a second or 2. This is due to the simplicity of the test case I've set up, and is not part of this bug.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The code should play the MP3 file and not throw an error.
      ACTUAL -
      Running this code via Gradle:

      $ gradle run
      :compileJava
      :processResources
      :classes
      :run
      Playing file:[snip]/src/main/resources/Ship_Bell-Mike_Koenig-1911209136.mp3
      Exception in Application start method
      java.lang.reflect.InvocationTargetException
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)
      at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
      at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)
      at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
      Caused by: java.lang.RuntimeException: Exception in Application start method
      at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
      at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$99(LauncherImpl.java:182)
      at java.lang.Thread.run(Thread.java:748)
      Caused by: MediaException: UNKNOWN : com.sun.media.jfxmedia.MediaException: Could not create player! : com.sun.media.jfxmedia.MediaException: Could not create player!
      at javafx.scene.media.MediaException.exceptionToMediaException(MediaException.java:146)
      at javafx.scene.media.MediaPlayer.init(MediaPlayer.java:511)
      at javafx.scene.media.MediaPlayer.<init>(MediaPlayer.java:414)
      at jfxmedia.Main.startPlaying(Main.java:27)
      at jfxmedia.Main.start(Main.java:19)
      at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$106(LauncherImpl.java:863)
      at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$119(PlatformImpl.java:326)
      at com.sun.javafx.application.PlatformImpl.lambda$null$117(PlatformImpl.java:295)
      at java.security.AccessController.doPrivileged(Native Method)
      at com.sun.javafx.application.PlatformImpl.lambda$runLater$118(PlatformImpl.java:294)
      at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
      at com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
      at com.sun.glass.ui.gtk.GtkApplication.lambda$null$450(GtkApplication.java:139)
      ... 1 more
      Caused by: com.sun.media.jfxmedia.MediaException: Could not create player!
      at com.sun.media.jfxmediaimpl.NativeMediaManager.getPlayer(NativeMediaManager.java:224)
      at com.sun.media.jfxmedia.MediaManager.getPlayer(MediaManager.java:104)
      at javafx.scene.media.MediaPlayer.init(MediaPlayer.java:467)
      ... 12 more
      Exception running application jfxmedia.Main

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      N/A -- the JVM does not crash

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      package jfxmedia;

      import javafx.application.*;
      import javafx.scene.media.Media;
      import javafx.scene.media.MediaPlayer;
      import javafx.stage.Stage;

      import java.io.File;

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

      @Override public void start(Stage stage)
      {
      startPlaying("src/main/resources/Ship_Bell-Mike_Koenig-1911209136.mp3");//throws MediaException
      // startPlaying("src/main/resources/Ship_Bell-Mike_Koenig-1911209136.wav");//works
      }

      private static void startPlaying(String file)
      {
      String uri = new File(file).toURI().toString();
      System.out.println("Playing " + uri);
      new MediaPlayer(new Media(uri)).play();
      }
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      None with OpenJDK, though this does work when I tried an Oracle JDK.

            pmangal Priyanka Mangal (Inactive)
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: