Skip to content
Snippets Groups Projects
Commit cb168084 authored by Tran Peter's avatar Tran Peter
Browse files

change(intro): add multiple videos to make the impression it's made by a real game studio #55

parent 4993a998
No related branches found
No related tags found
4 merge requests!74V1,!73Initial commit,!71Merge DataBase into Development,!4Merge UI into Development
......@@ -20,38 +20,55 @@ import java.util.ResourceBundle;
public class IntroController implements Initializable {
@FXML
public MediaView introMediaView;
public MediaView mediaView;
@FXML
public BorderPane introParent;
private final String fileName = "src/main/resources/textures/videos/";
// nextVideo() will iterate through this array so the next video will be played TODO: change the videos to non memes lmao
private final String[] videos = {"sony.mp4", "gamecube.mp4", "gameboy.mp4", "monke.mp4"};
private File file = new File(fileName + videos[0]);
private int counter = 0;
private MediaPlayer mediaPlayer;
@Override
public void initialize(URL url, ResourceBundle resourceBundle) {
introParent.setStyle("-fx-background-color: black;");
File file = new File("src/main/resources/textures/videos/pepe.mp4");
createMediaPlayer();
}
private void createMediaPlayer() {
Media media = new Media(file.toURI().toString());
MediaPlayer mediaPlayer = new MediaPlayer(media);
introMediaView.setMediaPlayer(mediaPlayer);
mediaPlayer = new MediaPlayer(media);
mediaView.setMediaPlayer(mediaPlayer);
// resizing once the scenes has been loaded to get width and height property
mediaPlayer.setOnReady(() -> {
introMediaView.fitWidthProperty().bind(introParent.getScene().widthProperty());
introMediaView.fitHeightProperty().bind(introParent.getScene().heightProperty());
mediaView.fitWidthProperty().bind(introParent.getScene().widthProperty());
mediaView.fitHeightProperty().bind(introParent.getScene().heightProperty());
});
mediaPlayer.setVolume(1);
mediaPlayer.setAutoPlay(true);
mediaPlayer.setOnEndOfMedia(() -> {
if (counter == videos.length - 1) {
videoEnd();
} else {
nextVideo();
}
});
// TODO: make any button pressed work
introParent.setOnMouseClicked((mouseEvent) -> {
mediaPlayer.dispose();
videoEnd();
if (counter == videos.length - 1) {
videoEnd();
} else {
nextVideo();
}
});
mediaPlayer.setOnEndOfMedia(this::videoEnd);
}
// TODO: maybe look into using SceneLoader class
// TODO: maybe look into using SceneLoader class
private void videoEnd() {
try {
mediaPlayer.dispose();
Parent root = FXMLLoader.load(Objects.requireNonNull(getClass().getResource("/fxml/MenuBorderPane.fxml")));
Stage stage = (Stage) introParent.getScene().getWindow();
Scene scene = new Scene(root);
......@@ -61,4 +78,11 @@ public class IntroController implements Initializable {
throw new RuntimeException();
}
}
private void nextVideo() {
mediaPlayer.dispose();
file = new File(fileName + videos[counter + 1]);
counter++;
createMediaPlayer();
}
}
......@@ -3,9 +3,8 @@
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.media.MediaView?>
<BorderPane fx:id="introParent" xmlns="http://javafx.com/javafx/21" xmlns:fx="http://javafx.com/fxml/1" fx:controller="de.hdm_stuttgart.battlearena.Controller.IntroController">
<center>
<MediaView fx:id="introMediaView" fitHeight="200.0" fitWidth="200.0" BorderPane.alignment="CENTER" />
<MediaView fx:id="mediaView" fitHeight="200.0" fitWidth="200.0" BorderPane.alignment="CENTER" />
</center>
</BorderPane>
File added
File added
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment