-1

I want to insert video into javaFX. Insert video from computer - Not from youtube or something. Play/pause/minimize buttons, borders are not needed.

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();
    }
}

My pr.mp4 file is inside project, not in package.

Stack trace:

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
user7291698
  • 1,972
  • 2
  • 15
  • 30

1 Answers1

0

The relevant line in your stack trace is:

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

You need to specify an URI string with a scheme as a construtor argument, as specified here.

So change your line from this:

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

to something like this:

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

Have a look at this question for more details: How to target a file (a path to it) in Java/JavaFX

Community
  • 1
  • 1
user7291698
  • 1,972
  • 2
  • 15
  • 30