简体   繁体   English

Debian Jessie JavaFX MediaPlayer:无法创建播放器

[英]Debian Jessie JavaFX MediaPlayer : Could not create player

I get this exception while running a java app with Ant configuration. 使用Ant配置运行Java应用程序时出现此异常。

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!

Here is my code : 这是我的代码:

@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();
}

Does anyone have an idean on how to solve this ? 有人对如何解决这个问题有想法吗?

I run it on Debian Jessie 64bits with Gnome 3.14.1 and Java : 我使用Gnome 3.14.1JavaDebian Jessie 64bits上运行它:

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)

Edit : 编辑:

Here is the stack trace i get when doing ant run : 这是我在执行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

Edit 2 : 编辑2:

I have libavcodec56 , libavformat56 and GLIB 2.42.1 installed. 我安装了libavcodec56libavformat56和GLIB 2.42.1。

# pkg-config --modversion glib-2.0
2.42.1

From the Certified System Configurations section of http://www.oracle.com/technetwork/java/javase/downloads/index.html http://www.oracle.com/technetwork/java/javase/downloads/index.html的“ 认证系统配置”部分中

You must install GLIB 2.28 in order to run JavaFX Media. 您必须安装GLIB 2.28才能运行JavaFX Media。

You must install the following in order to support AAC audio, MP3 audio, H.264 video, and HTTP Live Streaming: 必须安装以下组件才能支持AAC音频,MP3音频,H.264视频和HTTP Live Streaming:

  • libavcodec53 and libavformat53 on Ubuntu Linux 12.04 or equivalent. Ubuntu Linux 12.04或同等版本上的libavcodec53和libavformat53。

[...] [...]

  • VP6 video support does not require any third party modules. VP6视频支持不需要任何第三方模块。
  • On Linux platforms, installing libavformat automatically causes libavcodec to be installed. 在Linux平台上,安装libavformat会自动导致安装libavcodec。

Please double-check you have all the required libraries installed. 请仔细检查您是否已安装所有必需的库。

While the argument to Media 's constructor is a String , it must be formatted as a valid URI. Media的构造函数的参数为String ,必须将其格式化为有效的URI。 So instead of: 所以代替:

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

try this: 尝试这个:

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

There's a java bug in this case. 在这种情况下有一个Java错误。 Try downloading the new version which's been fixed (I downloaded the jdk 8u102). 尝试下载已修复的新版本(我下载了jdk 8u102)。 http://www.oracle.com/technetwork/pt/java/javase/downloads/jdk8-downloads-2133151.html http://www.oracle.com/technetwork/pt/java/javase/downloads/jdk8-downloads-2133151.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM