-1

I'm trying to do a video display on the javafx interface.

I put a correct path and tried more than one path and yet I get an error.

The code :

package com.company;

import java.io.File;

import javafx.application.Application;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.TilePane;
import javafx.scene.layout.VBox;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.media.MediaView;


public class Main extends Application {
    public static void main(String[] args) {
        launch(args);
    }


    @Override
    public void start(Stage primaryStage) {


        File file = new File("C:\\Users\\ahmad\\Desktop\\new\\sample-mp4-file.mp4");

        Media media = new Media(file.toURI().toString());

        MediaPlayer mediaplayer = new MediaPlayer(media);

        MediaView mediaView = new MediaView(mediaplayer);

        Button button1 = new Button("Play");
        Button button2 = new Button("Pause");
        Button button3 = new Button("Stop");

        button1.setOnAction(e -> {
            mediaplayer.play();
        });

        button2.setOnAction(e -> {
            mediaplayer.pause();
        });

        button3.setOnAction(e -> {
            mediaplayer.stop();
        });


        GridPane layout = new GridPane();
        layout.setHgap(10);
        layout.setVgap(10);

        //layout.add(mediaView, 0, 0);
        layout.add(mediaView, 1, 0);
        layout.add(button1, 0, 1);
        layout.add(button2, 1, 1);
        layout.add(button3, 2, 1);

        Scene scene = new Scene(layout, 300, 200);

        primaryStage.setTitle("CodersLegacy");
        primaryStage.setScene(scene);
        primaryStage.show();
    }
}

The error :

    Exception in Application start method
java.lang.reflect.InvocationTargetException
    at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:119)
    at java.base/java.lang.reflect.Method.invoke(Method.java:577)
    at javafx.graphics@18.0.1/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:465)
    at javafx.graphics@18.0.1/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:364)
    at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
    at java.base/java.lang.reflect.Method.invoke(Method.java:577)
    at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1081)
Caused by: java.lang.RuntimeException: Exception in Application start method
    at javafx.graphics@18.0.1/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:901)
    at javafx.graphics@18.0.1/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:196)
    at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.lang.IllegalAccessError: class com.sun.media.jfxmediaimpl.NativeMediaManager (in unnamed module @0x6ca50ed5) cannot access class com.sun.glass.utils.NativeLibLoader (in module javafx.graphics) because module javafx.graphics does not export com.sun.glass.utils to unnamed module @0x6ca50ed5
    at com.sun.media.jfxmediaimpl.NativeMediaManager.lambda$new$0(NativeMediaManager.java:111)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:569)
    at com.sun.media.jfxmediaimpl.NativeMediaManager.<init>(NativeMediaManager.java:108)
    at com.sun.media.jfxmediaimpl.NativeMediaManager$NativeMediaManagerInitializer.<clinit>(NativeMediaManager.java:78)
    at com.sun.media.jfxmediaimpl.NativeMediaManager.getDefaultInstance(NativeMediaManager.java:90)
    at com.sun.media.jfxmedia.MediaManager.canPlayProtocol(MediaManager.java:78)
    at com.sun.media.jfxmedia.locator.Locator.<init>(Locator.java:240)
    at javafx.scene.media.Media.<init>(Media.java:393)
    at com.company.Main.start(Main.java:33)
    at javafx.graphics@18.0.1/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:847)
    at javafx.graphics@18.0.1/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:484)
    at javafx.graphics@18.0.1/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:457)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
    at javafx.graphics@18.0.1/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:456)
    at javafx.graphics@18.0.1/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
    at javafx.graphics@18.0.1/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at javafx.graphics@18.0.1/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:184)
    ... 1 more
Exception running application com.company.Main
jewelsea
  • 141,332
  • 12
  • 351
  • 391
  • 1
    Does this answer your question? [Module error when running JavaFx media application](https://stackoverflow.com/questions/53237287/module-error-when-running-javafx-media-application) – kleopatra May 26 '22 at 04:03
  • The problem is not about javafx itself, it is about modularity. Check stacktrace – Giovanni Contreras May 26 '22 at 05:03
  • Does this answer your question? [IllegalAccessException: cannot access class C (in module M) because module M does not export C to module N](https://stackoverflow.com/questions/62659576/illegalaccessexception-cannot-access-class-c-in-module-m-because-module-m-doe) – Giovanni Contreras May 26 '22 at 05:08
  • 1
    Follow the [getting started documentation at openjfx.io](https://openjfx.io/openjfx-docs/), or use the [new JavaFX project wizard in Idea](https://www.jetbrains.com/help/idea/javafx.html). Also follow instructions at [Can not work with MediaPlayer class, javafx.media is not found](https://stackoverflow.com/questions/64016623/can-not-work-with-mediaplayer-class-javafx-media-is-not-found/64016989#64016989) to allow media to work in your app. – jewelsea May 26 '22 at 08:16

0 Answers0