JavaFX示例代码不播放视频,它只显示媒体播放器

时间:2014-12-11 09:17:33

标签: java javafx media-player media ubuntu-14.04

我在Netbeans上创建了一个示例代码 - Ubuntu 14.04-视频通常在同一路径的..例子之外播放。路径仅在我的机器上。

package javafxapplication1;

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.scene.media.MediaView;
import javafx.stage.Stage;

public class JavaFXApplication1 extends Application {

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

    @Override
    public void start(Stage primaryStage) {
        String workingDir = System.getProperty("user.dir");
        System.out.println("workingDir"+workingDir);
        File f = new File(workingDir, "the_appartition.flv");


        //try{

        //Media m = new Media(f.toURI().toString());

        Media m = new Media("http://192.168.1.251/test/videos/the_appartition.flv");
        System.out.println("media "+m.getSource());
        MediaPlayer mp = new MediaPlayer(m);
        MediaView mv = new MediaView(mp);

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

        primaryStage.setScene(new Scene(root, 960, 540));
        primaryStage.setTitle("Video Player 1");
        primaryStage.show();

        mp.play();
        /*}
        catch(Throwable t)
        {
              t.printStackTrace();

        }*/
    }
}

它可能是什么原因,它显示空白媒体播放器没有任何错误/异常。

1 个答案:

答案 0 :(得分:1)

此问题有一个固定的JIRA

[Linux] JavaFX Media does not run on Ubuntu 14.04

它在Java 8u40版本中修复。如果您真的想要运行它,您可能希望从JDK™ 8u40 Early Access Releases

下载并安装早期可用的JDK版本