mirror of
https://github.com/2OOP/pism.git
synced 2026-02-04 10:54:51 +00:00
Skip Button
This commit is contained in:
@@ -1,13 +1,16 @@
|
|||||||
package org.toop.app.view.displays;
|
package org.toop.app.view.displays;
|
||||||
|
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
|
import javafx.scene.control.Button;
|
||||||
import javafx.scene.control.ProgressBar;
|
import javafx.scene.control.ProgressBar;
|
||||||
import javafx.scene.layout.VBox;
|
import javafx.scene.layout.VBox;
|
||||||
import javafx.scene.paint.Color;
|
import javafx.scene.paint.Color;
|
||||||
|
import org.toop.framework.audio.AudioEventListener;
|
||||||
import org.toop.framework.audio.events.AudioEvents;
|
import org.toop.framework.audio.events.AudioEvents;
|
||||||
import org.toop.framework.eventbus.EventFlow;
|
import org.toop.framework.eventbus.EventFlow;
|
||||||
import javafx.geometry.Pos;
|
import javafx.geometry.Pos;
|
||||||
import javafx.scene.text.Text;
|
import javafx.scene.text.Text;
|
||||||
|
import org.toop.framework.eventbus.GlobalEventBus;
|
||||||
|
|
||||||
public class SongDisplay extends VBox {
|
public class SongDisplay extends VBox {
|
||||||
|
|
||||||
@@ -19,27 +22,26 @@ public class SongDisplay extends VBox {
|
|||||||
new EventFlow()
|
new EventFlow()
|
||||||
.listen(this::updateTheSong);
|
.listen(this::updateTheSong);
|
||||||
|
|
||||||
//TODO ADD NICER CSS
|
|
||||||
|
|
||||||
setAlignment(Pos.CENTER);
|
setAlignment(Pos.CENTER);
|
||||||
getStyleClass().add("song-display");
|
getStyleClass().add("song-display");
|
||||||
|
|
||||||
|
|
||||||
// TODO ADD GOOD SONG TITLES WITH ARTISTS DISPLAYED
|
// TODO ADD GOOD SONG TITLES WITH ARTISTS DISPLAYED
|
||||||
songTitle = new Text("song playing");
|
songTitle = new Text("song playing");
|
||||||
songTitle.setFill(Color.WHITE);
|
|
||||||
songTitle.getStyleClass().add("song-title");
|
songTitle.getStyleClass().add("song-title");
|
||||||
|
|
||||||
progressBar = new ProgressBar(0);
|
progressBar = new ProgressBar(0);
|
||||||
progressBar.getStyleClass().add("progress-bar");
|
progressBar.getStyleClass().add("progress-bar");
|
||||||
|
|
||||||
progressText = new Text("0:00/0:00");
|
progressText = new Text("0:00/0:00");
|
||||||
progressText.setFill(Color.WHITE);
|
|
||||||
progressText.getStyleClass().add("progress-text");
|
progressText.getStyleClass().add("progress-text");
|
||||||
|
|
||||||
//TODO ADD SKIP BUTTON
|
Button skipButton = new Button(">>");
|
||||||
|
skipButton.getStyleClass().setAll("skip-button");
|
||||||
|
skipButton.setOnAction( event -> {
|
||||||
|
GlobalEventBus.post(new AudioEvents.SkipMusic());
|
||||||
|
});
|
||||||
|
|
||||||
getChildren().addAll(songTitle, progressBar, progressText);
|
getChildren().addAll(songTitle, progressBar, progressText, skipButton);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateTheSong(AudioEvents.PlayingMusic event) {
|
private void updateTheSong(AudioEvents.PlayingMusic event) {
|
||||||
|
|||||||
@@ -13,31 +13,46 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.song-display {
|
.song-display {
|
||||||
-fx-background-color: rgba(30, 60, 30, 0.85);
|
|
||||||
-fx-background-radius: 10px;
|
|
||||||
-fx-padding: 8 12 8 12;
|
-fx-padding: 8 12 8 12;
|
||||||
-fx-spacing: 6px;
|
-fx-spacing: 6px;
|
||||||
-fx-alignment: center;
|
-fx-alignment: center;
|
||||||
-fx-effect: dropshadow(gaussian, rgba(0, 0, 0, 0.5), 6, 0.5, 0, 2);
|
-fx-effect: dropshadow(gaussian, rgba(0, 0, 0, 0.5), 6, 0.5, 0, 2);
|
||||||
-fx-min-width: 220px;
|
-fx-min-width: 220px;
|
||||||
-fx-max-width: 260px;
|
-fx-max-width: 260px;
|
||||||
-fx-text-fill: white;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.song-title {
|
.song-title {
|
||||||
-fx-font-size: 14px;
|
-fx-font-size: 14px;
|
||||||
-fx-font-weight: bold;
|
-fx-fill: white;
|
||||||
-fx-text-fill: white;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.progress-bar {
|
.progress-bar {
|
||||||
-fx-pref-width: 150px;
|
-fx-pref-width: 200px;
|
||||||
-fx-accent: red;
|
-fx-accent: red;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.progress-bar > .track {
|
||||||
|
-fx-background-radius: 30;
|
||||||
|
}
|
||||||
|
|
||||||
|
.progress-bar > .bar {
|
||||||
|
-fx-background-radius: 30px;
|
||||||
|
}
|
||||||
|
|
||||||
.progress-text {
|
.progress-text {
|
||||||
-fx-font-size: 11px;
|
-fx-font-size: 11px;
|
||||||
-fx-text-fill: white;
|
-fx-fill: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.skip-button {
|
||||||
|
-fx-background-color: transparent;
|
||||||
|
-fx-background-radius: 0;
|
||||||
|
-fx-cursor: hand;
|
||||||
|
-fx-text-fill: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.skip-button .text {
|
||||||
|
-fx-fill: white;
|
||||||
}
|
}
|
||||||
|
|
||||||
.button {
|
.button {
|
||||||
|
|||||||
@@ -13,31 +13,46 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.song-display {
|
.song-display {
|
||||||
-fx-background-color: rgba(30, 60, 30, 0.85);
|
|
||||||
-fx-background-radius: 10px;
|
|
||||||
-fx-padding: 8 12 8 12;
|
-fx-padding: 8 12 8 12;
|
||||||
-fx-spacing: 6px;
|
-fx-spacing: 6px;
|
||||||
-fx-alignment: center;
|
-fx-alignment: center;
|
||||||
-fx-effect: dropshadow(gaussian, rgba(0, 0, 0, 0.5), 6, 0.5, 0, 2);
|
-fx-effect: dropshadow(gaussian, rgba(0, 0, 0, 0.5), 6, 0.5, 0, 2);
|
||||||
-fx-min-width: 220px;
|
-fx-min-width: 220px;
|
||||||
-fx-max-width: 260px;
|
-fx-max-width: 260px;
|
||||||
-fx-text-fill: white;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.song-title {
|
.song-title {
|
||||||
-fx-font-size: 14px;
|
-fx-font-size: 14px;
|
||||||
-fx-font-weight: bold;
|
-fx-fill: white;
|
||||||
-fx-text-fill: white;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.progress-bar {
|
.progress-bar {
|
||||||
-fx-pref-width: 150px;
|
-fx-pref-width: 200px;
|
||||||
-fx-accent: red;
|
-fx-accent: red;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.progress-bar > .track {
|
||||||
|
-fx-background-radius: 30;
|
||||||
|
}
|
||||||
|
|
||||||
|
.progress-bar > .bar {
|
||||||
|
-fx-background-radius: 30px;
|
||||||
|
}
|
||||||
|
|
||||||
.progress-text {
|
.progress-text {
|
||||||
-fx-font-size: 11px;
|
-fx-font-size: 11px;
|
||||||
-fx-text-fill: white;
|
-fx-fill: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.skip-button {
|
||||||
|
-fx-background-color: transparent;
|
||||||
|
-fx-background-radius: 0;
|
||||||
|
-fx-cursor: hand;
|
||||||
|
-fx-text-fill: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.skip-button .text {
|
||||||
|
-fx-fill: white;
|
||||||
}
|
}
|
||||||
|
|
||||||
.button {
|
.button {
|
||||||
|
|||||||
@@ -13,31 +13,47 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.song-display {
|
.song-display {
|
||||||
-fx-background-color: rgba(30, 60, 30, 0.85);
|
|
||||||
-fx-background-radius: 10px;
|
|
||||||
-fx-padding: 8 12 8 12;
|
-fx-padding: 8 12 8 12;
|
||||||
-fx-spacing: 6px;
|
-fx-spacing: 6px;
|
||||||
-fx-alignment: center;
|
-fx-alignment: center;
|
||||||
-fx-effect: dropshadow(gaussian, rgba(0, 0, 0, 0.5), 6, 0.5, 0, 2);
|
-fx-effect: dropshadow(gaussian, rgba(0, 0, 0, 0.5), 6, 0.5, 0, 2);
|
||||||
-fx-min-width: 220px;
|
-fx-min-width: 220px;
|
||||||
-fx-max-width: 260px;
|
-fx-max-width: 260px;
|
||||||
-fx-text-fill: white;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.song-title {
|
.song-title {
|
||||||
-fx-font-size: 14px;
|
-fx-font-size: 14px;
|
||||||
-fx-font-weight: bold;
|
-fx-fill: black;
|
||||||
-fx-text-fill: white;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.progress-bar {
|
.progress-bar {
|
||||||
-fx-pref-width: 150px;
|
-fx-inner-background-color: black;
|
||||||
|
-fx-pref-width: 200px;
|
||||||
-fx-accent: red;
|
-fx-accent: red;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.progress-bar > .track {
|
||||||
|
-fx-background-radius: 30;
|
||||||
|
}
|
||||||
|
|
||||||
|
.progress-bar > .bar {
|
||||||
|
-fx-background-radius: 30px;
|
||||||
|
}
|
||||||
|
|
||||||
.progress-text {
|
.progress-text {
|
||||||
-fx-font-size: 11px;
|
-fx-font-size: 11px;
|
||||||
-fx-text-fill: white;
|
-fx-fill: black;
|
||||||
|
}
|
||||||
|
|
||||||
|
.skip-button {
|
||||||
|
-fx-background-color: transparent;
|
||||||
|
-fx-background-radius: 0;
|
||||||
|
-fx-cursor: hand;
|
||||||
|
-fx-text-fill: black;
|
||||||
|
}
|
||||||
|
|
||||||
|
.skip-button .text {
|
||||||
|
-fx-fill: black;
|
||||||
}
|
}
|
||||||
|
|
||||||
.button {
|
.button {
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ public class AudioEventListener<T extends AudioResource, K extends AudioResource
|
|||||||
new EventFlow()
|
new EventFlow()
|
||||||
.listen(this::handleStopMusicManager)
|
.listen(this::handleStopMusicManager)
|
||||||
.listen(this::handlePlaySound)
|
.listen(this::handlePlaySound)
|
||||||
|
.listen(this::handleSkipSong)
|
||||||
.listen(this::handleStopSound)
|
.listen(this::handleStopSound)
|
||||||
.listen(this::handleMusicStart)
|
.listen(this::handleMusicStart)
|
||||||
.listen(this::handleVolumeChange)
|
.listen(this::handleVolumeChange)
|
||||||
@@ -44,6 +45,10 @@ public class AudioEventListener<T extends AudioResource, K extends AudioResource
|
|||||||
this.soundEffectManager.play(event.fileName(), event.loop());
|
this.soundEffectManager.play(event.fileName(), event.loop());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void handleSkipSong(AudioEvents.SkipMusic event) {
|
||||||
|
this.musicManager.skip();
|
||||||
|
}
|
||||||
|
|
||||||
private void handleStopSound(AudioEvents.StopEffect event) {
|
private void handleStopSound(AudioEvents.StopEffect event) {
|
||||||
this.soundEffectManager.stop(event.fileName());
|
this.soundEffectManager.stop(event.fileName());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ public class MusicManager<T extends AudioResource> implements org.toop.framework
|
|||||||
private final List<T> resources;
|
private final List<T> resources;
|
||||||
private int playingIndex = 0;
|
private int playingIndex = 0;
|
||||||
private boolean playing = false;
|
private boolean playing = false;
|
||||||
|
private ScheduledExecutorService scheduler;
|
||||||
|
|
||||||
|
|
||||||
public MusicManager(List<T> resources) {
|
public MusicManager(List<T> resources) {
|
||||||
this.dispatcher = new JavaFXDispatcher();
|
this.dispatcher = new JavaFXDispatcher();
|
||||||
@@ -69,6 +71,15 @@ public class MusicManager<T extends AudioResource> implements org.toop.framework
|
|||||||
playCurrentTrack();
|
playCurrentTrack();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void skip() {
|
||||||
|
if (backgroundMusic.isEmpty()) return;
|
||||||
|
stop();
|
||||||
|
scheduler.shutdownNow();
|
||||||
|
playingIndex = playingIndex + 1;
|
||||||
|
playing = true;
|
||||||
|
playCurrentTrack();
|
||||||
|
}
|
||||||
|
|
||||||
// Used in testing
|
// Used in testing
|
||||||
void play(int index) {
|
void play(int index) {
|
||||||
if (playing) {
|
if (playing) {
|
||||||
@@ -104,8 +115,7 @@ public class MusicManager<T extends AudioResource> implements org.toop.framework
|
|||||||
|
|
||||||
private void setTrackRunnable(T track) {
|
private void setTrackRunnable(T track) {
|
||||||
|
|
||||||
|
scheduler = Executors.newSingleThreadScheduledExecutor();
|
||||||
ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
|
|
||||||
|
|
||||||
Runnable currentMusicTask = new Runnable() {
|
Runnable currentMusicTask = new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -21,6 +21,9 @@ public class AudioEvents extends EventsBase {
|
|||||||
/** Gives back the name of the song, the position its currently at (in seconds) and how long it takes (in seconds) */
|
/** Gives back the name of the song, the position its currently at (in seconds) and how long it takes (in seconds) */
|
||||||
public record PlayingMusic(String name, long currentPosition, long duration) implements GenericEvent {}
|
public record PlayingMusic(String name, long currentPosition, long duration) implements GenericEvent {}
|
||||||
|
|
||||||
|
/** Skips the song to the last second of the song resulting in a skip effect */
|
||||||
|
public record SkipMusic() implements GenericEvent {}
|
||||||
|
|
||||||
/** Change volume, choose type with {@link VolumeControl}. */
|
/** Change volume, choose type with {@link VolumeControl}. */
|
||||||
public record ChangeVolume(double newVolume, VolumeControl controlType) implements GenericEvent {}
|
public record ChangeVolume(double newVolume, VolumeControl controlType) implements GenericEvent {}
|
||||||
|
|
||||||
|
|||||||
@@ -5,4 +5,5 @@ import org.toop.framework.resource.types.AudioResource;
|
|||||||
public interface MusicManager<T extends AudioResource> extends AudioManager<T> {
|
public interface MusicManager<T extends AudioResource> extends AudioManager<T> {
|
||||||
void play();
|
void play();
|
||||||
void stop();
|
void stop();
|
||||||
|
void skip();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user