2017-01-20 79 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