hamza-don
hamza-don

Reputation: 465

Playing multiple videos JavaFx

I am totally new on JavaFx, I have a vbox with 3 ToggleButtons, When I click a Button a video will start playing on an another layout with 3 columns so I can play 3 videos on that layout by clicking the 3 ToggleButtons. I didn't found any help with tutorials. Can anyone suggest how to do it? Here's my 3 buttons code

   private static Scene createScene() {
    Group root = new Group();
    Scene scene = new Scene(root);

    // Création du layout pour les vidéos ainsi que du media builder pour
    // construire les vidéos
    VBox gridpane = new VBox(0.4);

    gridpane.setMaxWidth(Double.MAX_VALUE);
    gridpane.setStyle("-fx-border-style: solid;"
                + "-fx-border-width: 1;"
                + "-fx-border-color: black");
    Image progress = new Image(mediaplayer.class.getResourceAsStream("/cameras_images/im1.jpg"));
    Image im2 = new Image(mediaplayer.class.getResourceAsStream("/cameras_images/im2.jpg"));
    Image im3 = new Image(mediaplayer.class.getResourceAsStream("/cameras_images/im3.jpg"));


    ToggleButton bouton1 = new ToggleButton(" 1      ",new ImageView(progress));
      bouton1.setContentDisplay(ContentDisplay.RIGHT);
    ToggleButton bouton2 = new ToggleButton(" 2                 ",new ImageView(im2));
    bouton2.setContentDisplay(ContentDisplay.RIGHT);
    bouton2.setMaxWidth(Double.MAX_VALUE);


    ToggleButton bouton3 = new ToggleButton(" 3                                                           ",new ImageView(im3));
    bouton3.setContentDisplay(ContentDisplay.RIGHT);

    bouton3.setMaxWidth(Double.MAX_VALUE);

     gridpane.getChildren().add(bouton1); 
     gridpane.getChildren().add(bouton2);  
     gridpane.getChildren().add(bouton3); 


    root.getChildren().add(gridpane);


    return (scene);
}

Upvotes: 0

Views: 1204

Answers (1)

Markus Koivisto
Markus Koivisto

Reputation: 609

Right now the buttons do nothing. You need to add listeners to the buttons so that an action is triggered when the user toggles the buttons. Like so:

bouton1.setOnAction(new EventHandler<ActionEvent>() {
    @Override public void handle(ActionEvent e) {

        //if button is selected, start video
        //if button is deselected, stop video
    }
});

Upvotes: 1

Related Questions