2017-01-20 31 views
-1

我想将视频插入javaFX。从计算机插入视频 - 不是来自YouTube或其他内容。 播放/暂停/最小化按钮,不需要边框。如何在java中加载视频FX

import java.io.FileNotFoundException; 
import javafx.application.Application; 
import javafx.scene.Group; 
import javafx.scene.Scene; 
import javafx.scene.media.Media; 
import javafx.scene.media.MediaPlayer; 
import javafx.scene.media.MediaView; 
import javafx.stage.Stage; 

public class MediaMP4 extends Application { 
    Stage window; 
    Scene scene1; 


    public static void main(String[] args) { 
    launch(args); 
} 
@Override 
public void start(Stage primaryStage) throws FileNotFoundException { 

    window = primaryStage; 
    primaryStage.setTitle("Moves"); 


    Media media = new Media ("pr.mp4"); 
    MediaPlayer player = new MediaPlayer (media); 
    MediaView view = new MediaView (player); 


    Group full = new Group(); 
    full.getChildren().addAll(view); 


    scene1 = new Scene (full,600,600); 
    primaryStage.setScene(scene1); 
    window.show(); 

    player.play(); 
    } 
} 

我的pr.mp4文件在项目中,而不是在包中。

堆栈跟踪:

Exception in Application start method 
java.lang.reflect.InvocationTargetException 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 
at java.lang.reflect.Method.invoke(Unknown Source) 
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389) 
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328) 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 
at java.lang.reflect.Method.invoke(Unknown Source) 
at sun.launcher.LauncherHelper$FXHelper.main(Unknown Source) 
Caused by: java.lang.RuntimeException: Exception in Application start method 
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917) 
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$155(LauncherImpl.java:182) 
at java.lang.Thread.run(Unknown Source) 
Caused by: java.lang.IllegalArgumentException: uri.getScheme() == null! uri == 'pr.mp4' 
at com.sun.media.jfxmedia.locator.Locator.<init>(Locator.java:211) 
at javafx.scene.media.Media.<init>(Media.java:393) 
at vv.MediaMP4.start(MediaMP4.java:27) 
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863) 
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326) 
at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295) 
at java.security.AccessController.doPrivileged(Native Method) 
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294) 
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95) 
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method) 
at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191) 
... 1 more 
Exception running application vv.MediaMP4 
+0

控制台滴很长的错误日志。并不播放视频。 –

+0

没有错误日志,我们可能没有太多的事情可做。请包括错误日志 – Gikkman

+1

[编辑]您的问题,以包括[堆栈跟踪](http://stackoverflow.com/q/3988788/2775450)。确定代码中的哪一行引发异常(您可以在代码中看到行号;我们不能)。 –

回答

0

在您的堆栈跟踪相关线上:

Caused by: java.lang.IllegalArgumentException: uri.getScheme() == null! uri == 'pr.mp4'

您需要指定一个带有方案的URI字符串作为construtor参数,如指定的here

所以从这个更改行:

Media media = new Media ("pr.mp4");

到这样的事情:

Media media = new Media("file://c:/myproject/pr.mp4"));

看一看这个问题的更多细节:How to target a file (a path to it) in Java/JavaFX