Skip to content
This repository has been archived by the owner on Nov 29, 2017. It is now read-only.

Commit

Permalink
Integrate Audio
Browse files Browse the repository at this point in the history
  • Loading branch information
vapour101 committed Oct 29, 2017
1 parent 74310b2 commit 363849c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/main/java/ui/controller/BoardController.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package ui.controller;

import event.GameDrawerEventWrapper;
import event.GameEvent;
import event.HoverEvent;
import javafx.beans.value.ObservableValue;
import javafx.fxml.FXML;
Expand All @@ -28,10 +29,15 @@
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.media.MediaView;
import javafx.util.Duration;
import logic.gamehandler.GameHandler;
import ui.drawer.*;
import util.DrawCoords;

import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayDeque;
import java.util.Queue;
Expand All @@ -46,6 +52,10 @@ public class BoardController extends DockNodeController implements Initializable
Canvas boardCanvas;
Drawer gameDrawer;

@FXML
MediaView mediaView;
MediaPlayer mediaPlayer;

private GameHandler game;
private String fxmlLocation;
private boolean interactive;
Expand All @@ -60,6 +70,20 @@ public BoardController(GameHandler gameHandler, String resourcePath, boolean int
fxmlLocation = resourcePath;
sideBarItems = new ArrayDeque<>();
this.interactive = interactive;

mediaPlayer = null;
try {
Media media = new Media(getClass().getResource("/sound/sound6.mp3").toURI().toString());
mediaPlayer = new MediaPlayer(media);

gameHandler.subscribe(GameEvent.MOVE, event -> {
mediaPlayer.seek(Duration.ZERO);
mediaPlayer.play();
});
}
catch (URISyntaxException e) {
e.printStackTrace();
}
}

public final void addToSideBar(Node node) {
Expand All @@ -71,6 +95,9 @@ public void initialize(URL url, ResourceBundle resourceBundle) {
setupPanes();
constructCanvas();
setupSideBar();

if ( mediaPlayer != null )
mediaView.setMediaPlayer(mediaPlayer);
}

void setupPanes() {
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/fxml/localGame.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.SplitPane?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.media.MediaView?>
<AnchorPane xmlns:fx="http://javafx.com/fxml" xmlns="http://javafx.com/javafx"
fx:controller="ui.controller.BoardController">
<fx:script source="../script/splitterHiderButton.js"/>
Expand All @@ -18,5 +19,6 @@
AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"/>
</AnchorPane>
<VBox fx:id="sideBar" minWidth="10.0" prefHeight="200.0" prefWidth="100.0"/>
<MediaView fx:id="mediaView"/>
</SplitPane>
</AnchorPane>
File renamed without changes.

0 comments on commit 363849c

Please sign in to comment.