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

add(ui): add background music #14

parent 4d276737
No related branches found
No related tags found
4 merge requests!74V1,!73Initial commit,!71Merge DataBase into Development,!4Merge UI into Development
...@@ -23,6 +23,7 @@ public class CreditsController implements Initializable { ...@@ -23,6 +23,7 @@ public class CreditsController implements Initializable {
public void initialize(URL url, ResourceBundle resourceBundle) { public void initialize(URL url, ResourceBundle resourceBundle) {
parent.setStyle("-fx-background-color: black;"); parent.setStyle("-fx-background-color: black;");
createMediaPlayer(); createMediaPlayer();
MusicPlayerSingleton.getInstance().getMediaPlayer().dispose();
} }
private void createMediaPlayer() { private void createMediaPlayer() {
......
...@@ -4,12 +4,9 @@ import javafx.fxml.FXML; ...@@ -4,12 +4,9 @@ import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader; import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable; import javafx.fxml.Initializable;
import javafx.scene.Cursor; import javafx.scene.Cursor;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane; import javafx.scene.layout.BorderPane;
import javafx.scene.media.MediaPlayer; import javafx.scene.media.MediaPlayer;
import javafx.scene.media.MediaView; import javafx.scene.media.MediaView;
import javafx.stage.Stage;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
......
...@@ -2,7 +2,6 @@ package de.hdm_stuttgart.battlearena.Controller; ...@@ -2,7 +2,6 @@ package de.hdm_stuttgart.battlearena.Controller;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.scene.control.Button; import javafx.scene.control.Button;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox; import javafx.scene.layout.VBox;
import javafx.stage.Stage; import javafx.stage.Stage;
...@@ -35,5 +34,5 @@ public class MainMenuController { ...@@ -35,5 +34,5 @@ public class MainMenuController {
} }
// TODO: create skin selectiion scene // TODO: create skin selection scene
} }
...@@ -6,13 +6,16 @@ import javafx.geometry.Rectangle2D; ...@@ -6,13 +6,16 @@ import javafx.geometry.Rectangle2D;
import javafx.scene.control.Button; import javafx.scene.control.Button;
import javafx.scene.image.ImageView; import javafx.scene.image.ImageView;
import javafx.scene.layout.BorderPane; import javafx.scene.layout.BorderPane;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.stage.Screen; import javafx.stage.Screen;
import java.io.File;
import java.net.URL; import java.net.URL;
import java.util.ResourceBundle; import java.util.ResourceBundle;
public class MenuBorderPaneController implements Initializable { public class MenuBorderPaneController implements Initializable {
// TODO: change FXML variables to private. Don't know why it's not working when they're private // TODO: change FXML variables to private. Don't know why it's not working when they're private
@FXML @FXML
public BorderPane parent; public BorderPane parent;
@FXML @FXML
...@@ -21,6 +24,8 @@ public class MenuBorderPaneController implements Initializable { ...@@ -21,6 +24,8 @@ public class MenuBorderPaneController implements Initializable {
public ImageView imgLeft, imgRight; public ImageView imgLeft, imgRight;
private int counter = 0; private int counter = 0;
private final SceneLoader sceneLoader = new SceneLoader(); private final SceneLoader sceneLoader = new SceneLoader();
MediaPlayer musicPlayer;
@Override @Override
public void initialize(URL url, ResourceBundle resourceBundle) { public void initialize(URL url, ResourceBundle resourceBundle) {
parent.setCenter(sceneLoader.loadScene("MainMenu")); parent.setCenter(sceneLoader.loadScene("MainMenu"));
...@@ -31,6 +36,7 @@ public class MenuBorderPaneController implements Initializable { ...@@ -31,6 +36,7 @@ public class MenuBorderPaneController implements Initializable {
imgRight.setPreserveRatio(true); imgRight.setPreserveRatio(true);
imgLeft.setFitWidth(imageWidth); imgLeft.setFitWidth(imageWidth);
imgLeft.setPreserveRatio(true); imgLeft.setPreserveRatio(true);
backgroundMusic();
} }
public void easterEgg() { public void easterEgg() {
...@@ -40,4 +46,12 @@ public class MenuBorderPaneController implements Initializable { ...@@ -40,4 +46,12 @@ public class MenuBorderPaneController implements Initializable {
System.out.println("monke"); System.out.println("monke");
} }
} }
private void backgroundMusic() {
Media media = new Media(new File("src/main/resources/sound/music/cocBackgroundMusicTest.mp3").toURI().toString());
musicPlayer = new MediaPlayer(media);
musicPlayer.setCycleCount(MediaPlayer.INDEFINITE);
musicPlayer.play();
MusicPlayerSingleton.getInstance().setMediaPlayer(musicPlayer);
}
} }
package de.hdm_stuttgart.battlearena.Controller;
import javafx.scene.media.MediaPlayer;
public class MusicPlayerSingleton {
private static final MusicPlayerSingleton instance = new MusicPlayerSingleton();
private MediaPlayer mediaPlayer;
private MusicPlayerSingleton() {}
public static MusicPlayerSingleton getInstance() {
return instance;
}
public MediaPlayer getMediaPlayer() {
return mediaPlayer;
}
public void setMediaPlayer(MediaPlayer mediaPlayer) {
this.mediaPlayer = mediaPlayer;
}
}
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