-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame.java
More file actions
31 lines (29 loc) · 1.17 KB
/
game.java
File metadata and controls
31 lines (29 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Import all necessary classes
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.util.Duration;
import java.io.File;
// This class contains the method to play the game music using Media and MediaPlayer from JavaFX
class game {
// Initialize the media and mediaplayer used to set the game music
Media media = new Media(new File("PacMan/Resources/music/mertWaka.wav").toURI().toString());;
MediaPlayer mediaPlayer = new MediaPlayer(media);
// Method to play the game music
public void playMusic(){
mediaPlayer.play();
mediaPlayer.setAutoPlay(true);
mediaPlayer.setOnEndOfMedia(() -> mediaPlayer.seek(Duration.ZERO));
}
// Mertageddon Music
public void playMertageddonMusic(){
Media media = new Media(new File("PacMan/Resources/music/Mertageddon.wav").toURI().toString());
mediaPlayer = new MediaPlayer(media);
mediaPlayer.play();
mediaPlayer.setAutoPlay(true);
mediaPlayer.setOnEndOfMedia(() -> mediaPlayer.seek(Duration.ZERO));
}
// Method to stop the game music
public void stopMusic() {
mediaPlayer.stop();
}
}