0

ok so i have a mp4 file in my src folder in my project and it work's fine in eclipse but when i export it to a runnable jar file it doesn't work.

public void playRickRoll() throws MalformedURLException {
        StackPane spRickRoll = new StackPane();
        Stage stage = new Stage();
        stage.setResizable(false);
        stage.getIcons().add(new Image("60AKG.png"));

//      URL videoURL = getClass().getResource("RickRoll.mp4");
//      Media media = new Media(videoURL.toString());
        File f = new File("src/RickRoll.mp4");
        Media media = new Media(f.toURI().toString());
        MediaPlayer mediaPlayer = new MediaPlayer(media);
        mediaPlayer.setAutoPlay(true);
        MediaView mediaView = new MediaView();
        mediaView.setMediaPlayer(mediaPlayer);

        spRickRoll.getChildren().add(mediaView);
        stage.setScene(new Scene(spRickRoll, 460, 360));
        stage.show();
        mediaPlayer.play();

        stage.setOnCloseRequest(new EventHandler<WindowEvent>() {

            @Override
            public void handle(WindowEvent arg0) {
                mediaPlayer.stop();

            }
        });

    }
  • 1
    Looks like you want your MP4 file to be a **resource**. If that's correct, then using File is the wrong approach. Check out https://stackoverflow.com/questions/61531317/how-do-i-determine-the-correct-path-for-fxml-files-css-files-images-and-other. – Slaw Sep 12 '21 at 17:19
  • well it still works in eclipse but now when i try and run it in a jar file it gives me an error: unsupported protocol "rsrc" – itay bielski Sep 13 '21 at 05:22
  • Are you using Eclipse to package all your dependencies within your JAR file? – Slaw Sep 13 '21 at 20:51

0 Answers0