JavaFx MediaPlayer“无法创建播放器!” Ubuntu 14.04中的错误 [英] JavaFx MediaPlayer "Could not create player!" error in Ubuntu 14.04

查看:673
本文介绍了JavaFx MediaPlayer“无法创建播放器!” Ubuntu 14.04中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我安装了Ubuntu 14.04,当我实例化MediaPlayer时出现错误。

I have installed Ubuntu 14.04 and i'm getting an error when i instantiate a 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:

The problem is when i create the 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或其他播放器播放视频时,没有问题。

I have already installed ubuntu-restricted-extras, and all codecs needed to display mp4 videos. When i play the video with Vlc or other player, there is no problem.

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

May it be a JavaFx issue in Ubuntu 14.04?

我试过jre-1.8

I have tried with jre-1.8

推荐答案

我在Ubuntu 14.04上遇到了同样的问题,似乎jdk 8附带的最新版本的javaFx无法识别libavcodec54(Ubuntu 14.04附带)

I had the same issue on Ubuntu 14.04, it seems that the latest version of javaFx which comes with the jdk 8 doesn't recognize libavcodec54 (which comes shipped with Ubuntu 14.04)

为了能够使用视频:从Oracle网站安装最新版本的oracle(8u40)。

To be able to use video: Install the latest version of oracle (8u40) from the Oracle website.

步骤:


  1. 从( http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

将文件解压缩到/ usr / lib / jvm

Decompress the file to /usr/lib/jvm

tar -xvf jdk-8u40-linux- [arch_type] .tar.gz

mv jdk-8u40 / usr / lib / jvm

tar -xvf jdk-8u40-linux-[arch_type].tar.gz
mv jdk-8u40 /usr/lib/jvm

设置当前的java版本:

Set the current java version with:

update-alternatives --config java

update-alternatives --config javac

update-alternatives --config java
update-alternatives --config javac

要查看有关该错误的更多详细信息,请参阅: https://bugs.openjdk.java.net/browse/JDK-8094633

To see more details on the bug see: https://bugs.openjdk.java.net/browse/JDK-8094633

这篇关于JavaFx MediaPlayer“无法创建播放器!” Ubuntu 14.04中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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