我正在尝试使用 javafx 在 java 程序中播放 mp3 文件。我安装了依赖项libavcodec53
和libavformat53
这里提到.我使用了以下代码
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(); }
但我仍然收到错误"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)
有任何想法吗?
答案1
通过升级 Java 解决了这个问题。这是当前版本中的错误。
https://stackoverflow.com/questions/24848752/javafx-mp3-playback-ubuntu-14-04