Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
545 views
in Technique[技术] by (71.8m points)

JavaFx MediaPlayer "Could not create player!" error in Ubuntu 14.04

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

}

The problem is when i create the MediaPlayer:

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

The Exception message:

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)

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.

May it be a JavaFx issue in Ubuntu 14.04?

I have tried with jre-1.8

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can manually install the required version of av libraries downloading them from http://www.ubuntuupdates.org/. Search for packages libavutil51, libavformat53, libavcodec53

Download the ones matches the architecture of your JVM and use sudo dpkg -i libav*.deb to install them.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...