0

what i'm doing wrong? i was following this video (https://www.youtube.com/watch?v=7Gdxl2045l8) i wrote the same, except that it's on Intellij i still guess it's something related to config or javafx/jdk version !

Main.java file:

package sample;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class Main extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception{
        Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
        primaryStage.setTitle("Hello World");
        primaryStage.setScene(new Scene(root, 300, 275));
        primaryStage.show();
    }


    public static void main(String[] args) {
        launch(args);
    }
}

Controller.java file:

package sample;
import java.io.File;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Label;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.media.MediaView;
import javafx.stage.FileChooser;
public class Controller {

    private MediaPlayer mediaPlayer;


    private String filePath;

    @FXML
    private MediaView mediaView;
    @FXML
    private ResourceBundle resources;

    @FXML
    private URL location;

    @FXML
    private void handleButtonAction(ActionEvent event) {
        FileChooser fileChooser = new FileChooser();
        FileChooser.ExtensionFilter filter = new FileChooser.ExtensionFilter("Select a File", "*.mp4");
            fileChooser.getExtensionFilters().add(filter);
            File file = fileChooser.showOpenDialog(null);
            filePath = file.toURI().toString();

            if (filePath != null) {
                Media media = new Media(filePath);
                mediaPlayer = new MediaPlayer(media);
                mediaView.setMediaPlayer(mediaPlayer);
                mediaPlayer.play();
            }
    }

    @FXML
    void initialize() {

    }
}

sample.fxml file:

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.Button?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.StackPane?>
<?import javafx.scene.media.MediaView?>

<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.Controller">
   <center>
      <StackPane prefHeight="150.0" prefWidth="200.0" BorderPane.alignment="CENTER">
         <children>
            <MediaView fx:id="mediaView" fitHeight="200.0" fitWidth="200.0" />
         </children>
      </StackPane>
   </center>
   <bottom>
      <HBox alignment="CENTER" prefHeight="40.0" prefWidth="600.0" spacing="50.0" BorderPane.alignment="CENTER">
         <children>
            <Button mnemonicParsing="false" onAction="#handleButtonAction" text="Open" />
            <Button mnemonicParsing="false" text="Play" />
            <Button mnemonicParsing="false" text="pause" />
            <Button mnemonicParsing="false" text="Stop" />
         </children>
      </HBox>
   </bottom>
</BorderPane>

what i'm doing wrong? i was following this video (https://www.youtube.com/watch?v=7Gdxl2045l8) i wrote the same, except that it's on Intellij

i still guess it's something related to config or javafx/jdk version !

m.r_dino
  • 23
  • 3
  • 1
    Could you add your stacktrace? – Villat Oct 11 '19 at 23:10
  • did you add `jphonix` libarary to ide..? is your XML file ok?? – Dhanushka sasanka Oct 11 '19 at 23:21
  • An `InvocationTargetException` is never the fundamental error and does not tell us anything useful on its own. Please [edit] your question to add the entire [stack trace](https://stackoverflow.com/questions/3988788/what-is-a-stack-trace-and-how-can-i-use-it-to-debug-my-application-errors). – Slaw Oct 12 '19 at 03:16

0 Answers0