我最近升级到fedora 21.我真的很喜欢它,但是,javafx MediaPlayer不起作用.
根据JavaFX系统要求站点,对于要创建A MediaPlayer的Linux发行版,我需要:
libavcodec53
libavformat53
Run Code Online (Sandbox Code Playgroud)
我在Fedora存储库中找不到任何这些软件包(或者通过google搜索fedora 21找到任何关于它们的东西,我也检查了搜索fedora 20,但是我设法将它们从ATRpm安装到我的系统上成功并且仍然没运气.
我也装ffmpeg和ffmpeg-devel和ffmpeg-libs,而且转码,它仍然抛出这个异常.
这是我的StackTrace,如果你需要它:
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:875)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$147(LauncherImpl.java:157)
at com.sun.javafx.application.LauncherImpl$$Lambda$1/791452441.run(Unknown Source)
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.<init>(MediaPlayer.java:414)
at brainwaveentrainment.Main.start(Main.java:22)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$153(LauncherImpl.java:821)
at com.sun.javafx.application.LauncherImpl$$Lambda$55/632695357.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$166(PlatformImpl.java:323)
at com.sun.javafx.application.PlatformImpl$$Lambda$51/744796612.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$null$164(PlatformImpl.java:292)
at com.sun.javafx.application.PlatformImpl$$Lambda$53/731343915.run(Unknown …Run Code Online (Sandbox Code Playgroud) 我是Java和JavaFX的新手,我花了几年时间用QT开发Python,现在我正在用Java和JavaFX开发.
我正在开发一个程序,播放用户设置时间的音乐文件,然后停止.就这样,我需要从媒体对象获取持续时间以告诉音频何时停止(基于用户时间输入),但是,媒体对象上的getDuration()方法总是返回UNKNOWN.
我在Windows 8.1和openSuSE 13.2上使用JDK8u25(最新的稳定版本)(两者都有相同的问题):
File filestring = new File("my/file/dir/file.mp3")
Media file = new Media(filestring.toURI().toString());
file.getDuration(); // Returns UNKNOWN on both wav and mp3 files
file.getDuration().toMinutes()) // Also tested with toHours() toSeconds(), toMilli()...
// Above returns NaN because the file's duration is unknown
Run Code Online (Sandbox Code Playgroud)
就像一个测试,我把我的整个mp3音乐收藏(1000多首歌曲同时包含CBR和VBR)并让java遍历每个文件,所有这些都说明持续时间是未知的.我也试过来自多个不同来源的wav文件(只是为了确保它不是mp3格式),看看是否改变了......没有; 只有UNKNOWN持续时间.我还检查了以确保标签在适当位置,其他每个程序都说这些文件的文件属性中的长度或持续时间都很好.
奇怪的是,当我将Media对象传递给MediaPlayer时,文件播放效果非常好.虽然我可以使用外部库来获取长度,但是看到整个程序使用java和javafx库,这将更容易和更简化.