2

I tried to play simple mp3 file using javafx media player, and on windows everything works smoothly, how ever same code on Ubuntu 16.04 results in this error :

Exception in Application start method Exception in thread "main" 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$155(LauncherImpl.java:182) at java.lang.Thread.run(Thread.java:745) 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.(MediaPlayer.java:414) at Test.start(Test.java:24) at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863) at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326) at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295) at java.security.AccessController.doPrivileged(Native Method) at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(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$49(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:274) at com.sun.media.jfxmedia.MediaManager.getPlayer(MediaManager.java:118) at javafx.scene.media.MediaPlayer.init(MediaPlayer.java:467) ... 11 more

And i dont think i am making any mistake, did anyone have similar problems under ubuntu because i have no idea what is causing this.

public class Test extends Application {

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

}


@Override
public void start(Stage primaryStage) throws Exception {
    String musicFile = "/home/wrongway/Downloads/aaa.mp3";     // For example

    Media sound = new Media(new File(musicFile).toURI().toString());
    //  Media sound = new Media(musicFile.toString());
    System.out.println(musicFile.toString());
    MediaPlayer mediaPlayer = new MediaPlayer(sound);
    mediaPlayer.play();
}

}

ImRaphael
  • 204
  • 3
  • 25
  • Have u looked at http://stackoverflow.com/questions/24090356/javafx-mediaplayer-could-not-create-player-error-in-ubuntu-14-04? – mattias Jul 02 '16 at 20:11
  • i have tried installing all of that but with no success, i have java 1.8.0_92 version though... – ImRaphael Jul 02 '16 at 22:29

2 Answers2

1

My bad guys, i was not aware until now that ubuntu 16.04 was not among supported operating systems for javafx 1.8.

My apologies!

ImRaphael
  • 204
  • 3
  • 25
  • LOL, [a bug report](https://bugs.openjdk.java.net/browse/JDK-8150503) here. It's fixed in Java 9. – ice1000 Dec 08 '17 at 16:22
1

I was having the same problem. Turns out that MP3 files are not supported for JavaFX under Ubuntu 16.04, but works fine for WAV files.

Harshad Pansuriya
  • 20,189
  • 8
  • 67
  • 95