我在ubuntu上尝试过JavaFx MediaPlayer,但是在运行时它会告诉我
"MediaException: UNKNOWN : com.sun.media.jfxmedia.MediaException: Could not create player!"
任何人都知道如何解决它?
我已经尝试了大部分我可以google-ed,安装了ffmpeg,java8和jfxrt.jar。
对此有更简单的方法或模块测试方法吗?
提前谢谢!
描述:Ubuntu 15.04
java -version = Java(TM)SE运行时环境(版本1.8.0_77-b03)
System.out.println("Hello World");
File f = new File("a.mp3");
System.out.println("F=" + f.exists());
try {
final Media media = new Media(f.toURI().toString());
final MediaPlayer mediaPlayer = new MediaPlayer(media);
mediaPlayer.setAutoPlay(true);
mediaPlayer.play();
} catch (Exception e1) {
e1.printStackTrace();
}
Exception in thread "Thread-0" java.lang.IllegalStateException: Toolkit not initialised
[java] at com.sun.javafx.application.PlatformImpl.runLater(PlatformImpl.java:273)
[java] at com.sun.javafx.application.PlatformImpl.runLater(PlatformImpl.java:268)
[java] at javafx.application.Platform.runLater(Platform.java:[java] at javafx.scene.media.Media$_MetadataListener.onMetadata(Media.java:[java] at com.sun.media.jfxmediaimpl.MetadataParserImpl.done(MetadataParserImpl.java:120)
[java] at com.sun.media.jfxmediaimpl.platform.java.ID3MetadataParser.parse(ID3MetadataParser.java:237)
[java] at com.sun.media.jfxmediaimpl.MetadataParserImpl.run(MetadataParserImpl.java:103)
[java] MediaException: UNKNOWN : com.sun.media.jfxmedia.MediaException: Could not create player! : com.sun.media.jfxmedia.MediaException: Could not create player!
[java] at javafx.scene.media.MediaException.exceptionToMediaException(MediaException.java:146)
[java] at javafx.scene.media.MediaPlayer.init(MediaPlayer.java:511)
[java] at javafx.scene.media.MediaPlayer.<init>(MediaPlayer.java:414)
[java] at jarvis.main(jarvis.java:24)
[java] Caused by: com.sun.media.jfxmedia.MediaException: Could not create player!
[java] at com.sun.media.jfxmediaimpl.NativeMediaManager.getPlayer(NativeMediaManager.java:274)
[java] at com.sun.media.jfxmedia.MediaManager.getPlayer(MediaManager.java:118)
[java] at javafx.scene.media.MediaPlayer.init(MediaPlayer.java:467)
[java] ... 2 more