你好朋友我想在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(没有这样的文件或目录)
我解决了哪个方法?
答案 0 :(得分:0)
除非在启动java时明确设置它,否则String s=System.getProperty("/home/ubuntu/NetBeansProjects/Video/src");
将为null。所以你的代码相当于:
File f=new File("/media/video.flv");
答案 1 :(得分: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);