2

我正在使用 javafx-media player 开发我认为应该是一项简单的任务,它将播放存储在本地硬盘驱动器上的 mp3 文件,在用户默认的音乐文件夹路径中(使用 fedora)。我可以从命令行很好地播放所有 mp3 文件,但是当我尝试通过 javafx.scene.media 库播放时,javafx 一直告诉我 mp3 是一种受支持的媒体类型。我已经下载了我能找到的所有图书馆,但无济于事。这是实际尝试打开文件并播放媒体的代码:

第一次尝试:

 public void playTrack( String audioFileName ) {
    System.out.println("going to play the file "+audioFileName);
    String filename = System.getProperty("user.home")+"/"+audioFileName;
    File audioFile = new File( filename);
    Media audioFileStream= null;
    try {
        audioFileStream = new Media(audioFile.toURI().toURL().toString());
    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    MediaPlayer mediaPlayer = new MediaPlayer(audioFileStream);
    mediaPlayer.play();
}

方法二:

public void playTrack( String audioFileName ) {
    System.out.println("going to play the file "+audioFileName);
    String source = new File(System.getProperty("user.home")+"/"+audioFileName).toURI().toString();
    //String source = new File("07-Basket-Case.mp3").toURI().toString();
    System.out.println("going to play "+source);
    Media media = null;
    media = new Media(source);
    MediaPlayer mediaPlayer = new MediaPlayer(media);
    mediaPlayer.play();
}

两者都产生完全相同的错误结果,如下所示:

将播放文件:/home/cpeddie/workspace/parnassusfx/07-Basket-Case.mp3 线程“JavaFX 应用程序线程”中的异常 MediaException:MEDIA_UNSUPPORTED:com.sun.media.jfxmedia.MediaException:“不支持错误媒体音频格式” : com.sun.media.jfxmedia.MediaException: javafx.scene.media.MediaException.exceptionToMediaException(MediaException.java:125) 处 javafx.scene.media.MediaPlayer.init(MediaPlayer.java: 474) 在 javafx.scene.media.MediaPlayer.(MediaPlayer.java:383) 在 com.promptu.parnassusfx.sample.music.MusicController.playTrack(MusicController.java:218) 在 com.promptu.parnassusfx.sample.music。 MusicController$3$1$1.handle(MusicController.java:357) at com.promptu.parnassusfx.sample.music.MusicController$3$1$1.handle(MusicController.java:1) 在 com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:217) 在 com.sun.javafx.event.EventHandlerManager 的 com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:69) .dispatchBubblingEvent(EventHandlerManager.java:170) 在 com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:38) 在 com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:37) 在 com. sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92) 在 com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35) 在 com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl. java:92) 在 com.sun.javafx.event.BasicEventDispatcher。dispatchEvent(BasicEventDispatcher.java:35) 在 com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92) 在 com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35) 在 com.sun .javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92) 在 com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35) 在 com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java :92) 在 com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92) 在 com.sun.javafx.event 的 com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35)。 BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35) 在 com.sun.javafx.event.EventDispatchChainImpl。dispatchEvent(EventDispatchChainImpl.java:92) at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35) at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92) at com.sun .javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35) 在 com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92) 在 com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java :53) 在 com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:28) 在 javafx.event.Event.fireEvent(Event.java:171) 在 javafx.scene.Node.fireEvent(Node.java: 6867) 在 javafx.scene.control.Button.fire(Button.java:179) 在 com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:193) 在 com.sun.javafx.scene 。控制。skin.SkinBase$4.handle(SkinBase.java:336) at com.sun.javafx.scene.control.skin.SkinBase$4.handle(SkinBase.java:329) at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent( CompositeEventHandler.java:64) 在 com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:217) 在 com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:170) 在 com.sun.javafx .event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:38) at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:37) at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92 ) 在 com.sun.javafx.event 的 com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35)。EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92) 在 com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35) 在 com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92) 在 com .sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35) 在 com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92) 在 com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher .java:35) 在 com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35) 在 com.sun.javafx.eventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92) 在 com.sun.javafx。 com.sun.javafx.event 中的 event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)。BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35) 在 com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92) 在 com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35) 在 com .sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92) 在 com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35) 在 com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl .java:92) 位于 com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92) 的 com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35)。 com.sun.javafx.event.EventUtil 中的 event.EventUtil.fireEventImpl(EventUtil.java:53)。fireEvent(EventUtil.java:33) at javafx.event.Event.fireEvent(Event.java:171) at javafx.scene.Scene$MouseHandler.process(Scene.java:3311) at javafx.scene.Scene$MouseHandler.process (Scene.java:3151) 在 javafx.scene.Scene$MouseHandler.access$1900(Scene.java:3106) 在 javafx.scene.Scene.impl_processMouseEvent(Scene.java:1563) 在 javafx.scene.Scene$ScenePeerListener.mouseEvent (Scene.java:2248) 在 com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:250) 在 com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java :173) 在 java.security.AccessController.doPrivileged(Native Method) 在 com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:292) 在 com.sun.glass.ui.View。com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method) 上 com.sun.glass.ui.View.notifyMouse(View.java:924) 上的 handleMouseEvent(View.java:530)。 glass.ui.gtk.GtkApplication$3$1.run(GtkApplication.java:89) at java.lang.Thread.run(Thread.java:724) 原因:com.sun.media.jfxmedia.MediaException:“错误媒体音频com.sun.media.jfxmediaimpl.platform.gstreamer.GSTMedia.init(GSTMedia.java:50) 的 com.sun.media.jfxmediaimpl.MediaUtils.nativeError(MediaUtils.java:331) 的格式不受支持。 media.jfxmediaimpl.platform.gstreamer.GSTMedia.(GSTMedia.java:33) 在 com.sun.media.jfxmediaimpl.platform.gstreamer.GSTMediaPlayer.(GSTMediaPlayer.java:39) 在 com.sun.media.jfxmediaimpl.platform。 com.sun.media.jfxmediaimpl.platform 上的 gstreamer.GSTPlatform.prerollMediaPlayer(GSTPlatform.java:100)。PlatformManager.createMediaPlayer(PlatformManager.java:173) at com.sun.media.jfxmediaimpl.NativeMediaManager.getPlayer(NativeMediaManager.java:260) at com.sun.media.jfxmedia.MediaManager.getPlayer(MediaManager.java:139) at javafx .scene.media.MediaPlayer.init(MediaPlayer.java:431) ... 75 更多

我还应该提到,我正在使用运行在 OS 10.8.5 的 MacBook Pro 上的 VMWare fusion 来开发它。运行 Fedora 19。

任何帮助将不胜感激!

4

1 回答 1

3

花了大约一天半的时间才弄明白,但需要安装以下软件包:

dirac-libs-1.0.2-9.fc18.i686.rpm

libavcodec52-0.7.15-32.fc18.i686.rpm

libavformat52-0.7.15-32.fc18.i686.rpm

libavutil50-0.7.15-32.fc18.i686.rpm

libxavs1-0.1.51-2.fc18.i686.rpm

一旦安装了这些,javafx 就会像魅力一样播放音乐。

于 2013-10-25T00:17:57.360 回答