2016-03-08 46 views
0

運行帶有Ant配置的Java應用程序時,出現此異常。Debian Jessie JavaFX MediaPlayer:無法創建播放器

Exception in thread "JavaFX Application Thread" MediaException: UNKNOWN : com.sun.media.jfxmedia.MediaException: Could not create player! : com.sun.media.jfxmedia.MediaException: Could not create player! 

這裏是我的代碼:

@Override public void start(Stage stage) { 
    final Scene scene = new Scene(((Viewer)viewer).getPanel()); 
    Media theme = new Media(getHostServices().getDocumentBase() + "src/sound/theme_bttf.mp3"); 
    new MediaPlayer(theme).play(); 
} 

有沒有人對如何解決這一個idean?

我對Debian的傑西64位侏儒3.14.1的Java運行:

java version "1.8.0_74" 
Java(TM) SE Runtime Environment (build 1.8.0_74-b02) 
Java HotSpot(TM) 64-Bit Server VM (build 25.74-b02, mixed mode) 

編輯:

這裏是堆棧跟蹤做ant run當我得到:

run: 
[echo] ================ Run Object Main ================ 
[java] Gtk-Message: Failed to load module "canberra-gtk-module" 
[java] Exception in Application start method 
[java] java.lang.reflect.InvocationTargetException 
[java]  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
[java]  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
[java]  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
[java]  at java.lang.reflect.Method.invoke(Method.java:498) 
[java]  at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389) 
[java]  at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328) 
[java]  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
[java]  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
[java]  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
[java]  at java.lang.reflect.Method.invoke(Method.java:498) 
[java]  at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767) 
[java] Caused by: java.lang.RuntimeException: Exception in Application start method 
[java]  at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917) 
[java]  at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$155(LauncherImpl.java:182) 
[java]  at java.lang.Thread.run(Thread.java:745) 
[java] Caused by: 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 alpha.Main.start(Main.java:71) 
[java]  at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863) 
[java]  at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326) 
[java]  at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295) 
[java]  at java.security.AccessController.doPrivileged(Native Method) 
[java]  at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294) 
[java]  at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95) 
[java]  at com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method) 
[java]  at com.sun.glass.ui.gtk.GtkApplication.lambda$null$49(GtkApplication.java:139) 
[java]  ... 1 more 
[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]  ... 11 more 
[java] Exception running application alpha.Main 
[java] Java Result: 1 

編輯2:

我已經libavcodec56libavformat56和GLIB 2.42.1安裝。

# pkg-config --modversion glib-2.0 
2.42.1 
+0

請向我們展示完整的堆棧跟蹤。 – Puce

+0

@Puce剛添加堆棧跟蹤到我的帖子 – Senorihl

回答

1

http://www.oracle.com/technetwork/java/javase/downloads/index.html

Certified System Configurations 部分必須以運行JavaFX的媒體安裝GLIB 2.28。

您必須安裝以下以支持AAC音頻,MP3音頻 ,H.264視頻,和HTTP實時流:在Ubuntu Linux 12.04或同等

  • libavcodec53和libavformat53。

[...]

  • VP6視頻的支持,不需要任何第三方模塊。
  • 在Linux平臺上,安裝libavformat會自動導致安裝libavcodec。

請仔細檢查您是否安裝了所有必需的庫。

+0

我有libavcodec56和libavformat56安裝 – Senorihl

+0

@Senorihl我猜你還安裝了GLIB 2.28? – Puce

+0

我猜...我可以使用aptitude的名稱是什麼? – Senorihl

0

雖然Media的構造函數的參數是String,但它必須格式化爲有效的URI。因此,而不是:

Media theme = new Media(getHostServices().getDocumentBase() + "src/sound/theme_bttf.mp3"); 

試試這個:

Media theme = new Media(new File(getHostServices().getDocumentBase() + "src/sound/theme_bttf.mp3").toUri().toString());