JavaFX和“MediaException:UNKNOWN ...无法创建播放器!” [英] JavaFX and "MediaException: UNKNOWN ... Could not create player!"

查看:150
本文介绍了JavaFX和“MediaException:UNKNOWN ...无法创建播放器!”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Ok, so I need to program a more or less simple video player and I chosen JavaFX for this task. Till now I've written a VERY simple (and ought to be working) app, but it constantly throws the same error:

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(双通.mp4)播放输出,但它没有奏效。然后我从这里下载了一个样本.flv文件。它没有用,所以我尝试了一个mp3文件,但问题仍然存在。我甚至试图在Windows和Linux上编译它,但没有任何效果。

I'm just beginning my adventure with JavaFX and before posting here I've read similar topics about this problem and most of the times the problem was with the type of media encoding. So first I've tried to play an output from Handbrake (Two-Pass .mp4) but it didn't worked. Then I downloaded a sample .flv file from HERE. It didn't worked too, so I tried a mp3 file, but the problem still persisted. I have even tried to compile it on Windows and on Linux, but nothing worked.

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

For the sake of clarity, the code looks like this:

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();
    }
}


推荐答案

好的,最后我找到了问题的原因 - 我通过视频路径文件的方式是错误的:

Ok, finally I found the cause of the problem - the way I passed the video path file was wrong:

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

我应该使用媒体媒体=新媒体(新文件(file:///home/winged/IdeaProjects/MoviePlayer/video/barsandtone.flv)。toURI()。toString());

这篇关于JavaFX和“MediaException:UNKNOWN ...无法创建播放器!”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆