Ubuntu 14.04 中的 JavaFx MediaPlayer "Could not create player!"错误

标签 javafx ubuntu-14.04

我已经安装了 Ubuntu 14.04,但在实例化 MediaPlayer 时遇到错误。

package mediatest;

import java.io.File;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.stage.Stage;

/**
 *
 * @author DESARROLLO
 */
public class MediaTest extends Application {

    @Override
    public void start(Stage primaryStage) {
        Button btn = new Button();
        btn.setText("Say 'Hello World'");
        btn.setOnAction(new EventHandler<ActionEvent>() {

            @Override
            public void handle(ActionEvent event) {
                Media media = new Media(new File("rotate.mp4").toURI().toASCIIString());
                MediaPlayer player = new MediaPlayer(media);
            }
        });

        StackPane root = new StackPane();
        root.getChildren().add(btn);

        Scene scene = new Scene(root, 300, 250);

        primaryStage.setTitle("Hello World!");
        primaryStage.setScene(scene);
        primaryStage.show();
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        launch(args);
    }

}

问题是当我创建 MediaPlayer 时:

Media media = new Media(new File("rotate.mp4").toURI().toASCIIString());
MediaPlayer player = new MediaPlayer(media);

异常消息:

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 javafxapplication2.FXMLDocumentController.handleButtonAction(FXMLDocumentController.java:34)

我已经安装了 ubuntu-restricted-extras,以及显示 mp4 视频所需的所有编解码器。 当我用Vlc或其他播放器播放视频时,没有问题。

这可能是 Ubuntu 14.04 中的 JavaFx 问题吗?

我尝试过jre-1.8

最佳答案

您可以手动安装所需版本的AV库,从http://www.ubuntuupdates.org/下载它们。搜索包 libavutil51libavformat53libavcodec53

下载与您的 JVM 架构相匹配的文件并使用 sudo dpkg -i libav*.deb 来安装它们。

关于Ubuntu 14.04 中的 JavaFx MediaPlayer "Could not create player!"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24090356/

相关文章:

mysql - MySQL Workbench 6.1.7 中未出现执行计划选项卡

c++ - 编译并运行文件夹中提供的 MySQL++ 和 C++ 示例

ubuntu - 使用 eyed3 递归删除 mp3 中的所有嵌入图像

java - 如何使 RadioButton 看起来像 JavaFX 中的常规 Button

java - 无法从 Soap 响应中的节点检索文本内容

JavaFX 11 : IllegalAccessError when creating Label

node.js - gulp-watch 只运行一次

javafx IllegalArgumentException(已设置为另一个场景的根)

javafx 通过代码点击按钮

linux - Chef 从命令行管理报告