gpt4 book ai didi

JavaFX 和 "MediaException: UNKNOWN ... Could not create player!"

转载 作者:行者123 更新时间:2023-11-30 08:19:43 24 4
gpt4 key购买 nike

好的,所以我需要编写一个或多或少简单的视频播放器,我选择了 JavaFX 来完成这项任务。到目前为止,我已经编写了一个非常简单(并且应该可以正常工作)的应用程序,但它不断抛出相同的错误:

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/1573468.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 player.MoviePlayer.start(MoviePlayer.java:23)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$153(LauncherImpl.java:821)
at com.sun.javafx.application.LauncherImpl$$Lambda$55/17730007.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$166(PlatformImpl.java:323)
at com.sun.javafx.application.PlatformImpl$$Lambda$50/11354414.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$null$164(PlatformImpl.java:292)
at com.sun.javafx.application.PlatformImpl$$Lambda$53/4845991.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$165(PlatformImpl.java:291)
at com.sun.javafx.application.PlatformImpl$$Lambda$51/26970262.run(Unknown Source)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
at com.sun.glass.ui.gtk.GtkApplication.lambda$null$45(GtkApplication.java:126)
at com.sun.glass.ui.gtk.GtkApplication$$Lambda$43/4959060.run(Unknown Source)
... 1 more
Caused by: com.sun.media.jfxmedia.MediaException: Could not create player!
at com.sun.media.jfxmediaimpl.NativeMediaManager.getPlayer(NativeMediaManager.java:222)
at com.sun.media.jfxmedia.MediaManager.getPlayer(MediaManager.java:104)
at javafx.scene.media.MediaPlayer.init(MediaPlayer.java:467)
... 16 more

Process finished with exit code 1

我才刚刚开始我的 JavaFX 探索之旅,在发帖之前,我已经阅读了有关此问题的类似主题,大多数时候问题出在媒体编码类型上。因此,首先我尝试播放 Handbrake (Two-Pass .mp4) 的输出,但没有奏效。然后我从 HERE 下载了一个示例 .flv 文件.它也没有用,所以我尝试了一个mp3文件,但问题仍然存在。我什至尝试在 Windows 和 Linux 上编译它,但没有任何效果。

为了清楚起见,代码如下所示:

package player;

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.media.MediaView;
import javafx.scene.paint.Color;
import javafx.stage.Stage;

public class MoviePlayer extends Application {

public static void main(String[] args) {
launch(args);
}

@Override
public void start(Stage stage) throws Exception {
Group root = new Group();

Media media = new Media("file:///home/winged/IdeaProjects/MoviePlayer/video/barsandtone.flv");
MediaPlayer player = new MediaPlayer(media);
MediaView view = new MediaView(player);

player.setAutoPlay(true);

root.getChildren().add(view);
Scene scene = new Scene(root, 400, 400, Color.BLACK);
stage.setScene(scene);
stage.show();

player.play();
}
}

最佳答案

好吧,终于找到问题的原因——我传视频路径文件的方式不对:

而不是使用 Media media = new Media("file:///home/winged/IdeaProjects/MoviePlayer/video/barsandtone.flv");

我应该使用 Media media = new Media(new File("file:///home/winged/IdeaProjects/MoviePlayer/video/barsandtone.flv").toURI().toString());

关于JavaFX 和 "MediaException: UNKNOWN ... Could not create player!",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26625362/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com