JavaFX mp3 playback Ubuntu 14.04

风流意气都作罢 提交于 2021-02-10 08:21:45

问题


I am trying to play mp3 file in java program using javafx. I installed dependencies libavcodec53 and libavformat53 mentioned here. I used following code

  public void play(String path_to_song){
        JFXPanel fxPanel = new JFXPanel();
        String song = new File(path_to_song).toURI().toString();
        Media audio =null;
        audio = new Media(song);
        MediaPlayer mediaPlayer = new MediaPlayer(audio);
        mediaPlayer.play();
}

But I still got error "Error media audio format unsupported"

Exception in thread "main" MediaException: MEDIA_UNSUPPORTED : com.sun.media.jfxmedia.MediaException: "Error media audio format unsupported" : com.sun.media.jfxmedia.MediaException: "Error media audio format unsupported"
    at javafx.scene.media.MediaException.exceptionToMediaException(MediaException.java:125)
    at javafx.scene.media.MediaPlayer.init(MediaPlayer.java:474)
    at javafx.scene.media.MediaPlayer.<init>(MediaPlayer.java:383)
    at playback.Player.play(Player.java:39)
    at engine.Execute.main(Execute.java:15)
Caused by: com.sun.media.jfxmedia.MediaException: "Error media audio format unsupported"
    at com.sun.media.jfxmediaimpl.MediaUtils.nativeError(MediaUtils.java:331)
    at com.sun.media.jfxmediaimpl.platform.gstreamer.GSTMedia.init(GSTMedia.java:50)
    at com.sun.media.jfxmediaimpl.platform.gstreamer.GSTMedia.<init>(GSTMedia.java:33)
    at com.sun.media.jfxmediaimpl.platform.gstreamer.GSTMediaPlayer.<init>(GSTMediaPlayer.java:39)
    at com.sun.media.jfxmediaimpl.platform.gstreamer.GSTPlatform.prerollMediaPlayer(GSTPlatform.java:100)
    at com.sun.media.jfxmediaimpl.platform.PlatformManager.createMediaPlayer(PlatformManager.java:173)
    at com.sun.media.jfxmediaimpl.NativeMediaManager.getPlayer(NativeMediaManager.java:264)
    at com.sun.media.jfxmedia.MediaManager.getPlayer(MediaManager.java:139)
    at javafx.scene.media.MediaPlayer.init(MediaPlayer.java:431)

Any ideas?

来源:https://stackoverflow.com/questions/24848752/javafx-mp3-playback-ubuntu-14-04

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!