0

你好朋友我想在 JavaFx 中播放视频我尝试下面的代码

public class Video extends Application {

@Override
public void start(Stage stage) throws Exception {



    String s=System.getProperty("/home/ubuntu/NetBeansProjects/Video/src"); 
    File f=new File(s, "/media/video.flv");
    Media m=new Media(f.toURI().toString());
    MediaPlayer mp=new MediaPlayer(m);
    MediaView mv=new MediaView(mp);

    StackPane root=new StackPane();
    root.getChildren().add(mv);
    stage.setScene(new Scene(root,400,400));
    stage.setTitle("Video");
    stage.show();
    mp.play();

}


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

}

我收到类似 MediaException: MEDIA_UNAVAILABLE : /media/video.flv 的错误(没有这样的文件或目录)

我用什么方法解决?

4

2 回答 2

0

除非您在启动 java 时明确设置它,String s=System.getProperty("/home/ubuntu/NetBeansProjects/Video/src");否则将为空。所以你的代码相当于:

File f=new File("/media/video.flv");
于 2012-12-31T07:09:24.800 回答
0
    File f = new File("D:\\Project Files\\Videos\\Business\\Accounting\\Free\\Careers in Accounting.mp4");

    Media media = new Media(f.toURI().toString());
    MediaView mv = new MediaView();

    MediaPlayer mp = new MediaPlayer(media);
    mv.setMediaPlayer(mp);
于 2017-12-10T05:28:17.353 回答