Issue
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();
}
}
Solution
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!
Answered By - ImRaphael
Answer Checked By - Candace Johnson (JavaFixing Volunteer)