Skip Button

This commit is contained in:
michiel
2025-10-16 13:35:41 +02:00
parent abc173a1ee
commit 30f797022c
12 changed files with 97 additions and 30 deletions

View File

@@ -1,13 +1,16 @@
package org.toop.app.view.displays;
import javafx.application.Platform;
import javafx.scene.control.Button;
import javafx.scene.control.ProgressBar;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import org.toop.framework.audio.AudioEventListener;
import org.toop.framework.audio.events.AudioEvents;
import org.toop.framework.eventbus.EventFlow;
import javafx.geometry.Pos;
import javafx.scene.text.Text;
import org.toop.framework.eventbus.GlobalEventBus;
public class SongDisplay extends VBox {
@@ -19,27 +22,26 @@ public class SongDisplay extends VBox {
new EventFlow()
.listen(this::updateTheSong);
//TODO ADD NICER CSS
setAlignment(Pos.CENTER);
getStyleClass().add("song-display");
// TODO ADD GOOD SONG TITLES WITH ARTISTS DISPLAYED
songTitle = new Text("song playing");
songTitle.setFill(Color.WHITE);
songTitle.getStyleClass().add("song-title");
progressBar = new ProgressBar(0);
progressBar.getStyleClass().add("progress-bar");
progressText = new Text("0:00/0:00");
progressText.setFill(Color.WHITE);
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) {

View File

@@ -13,31 +13,46 @@
}
.song-display {
-fx-background-color: rgba(30, 60, 30, 0.85);
-fx-background-radius: 10px;
-fx-padding: 8 12 8 12;
-fx-spacing: 6px;
-fx-alignment: center;
-fx-effect: dropshadow(gaussian, rgba(0, 0, 0, 0.5), 6, 0.5, 0, 2);
-fx-min-width: 220px;
-fx-max-width: 260px;
-fx-text-fill: white;
}
.song-title {
-fx-font-size: 14px;
-fx-font-weight: bold;
-fx-text-fill: white;
-fx-fill: white;
}
.progress-bar {
-fx-pref-width: 150px;
-fx-pref-width: 200px;
-fx-accent: red;
}
.progress-bar > .track {
-fx-background-radius: 30;
}
.progress-bar > .bar {
-fx-background-radius: 30px;
}
.progress-text {
-fx-font-size: 11px;
-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 {

View File

@@ -13,31 +13,46 @@
}
.song-display {
-fx-background-color: rgba(30, 60, 30, 0.85);
-fx-background-radius: 10px;
-fx-padding: 8 12 8 12;
-fx-spacing: 6px;
-fx-alignment: center;
-fx-effect: dropshadow(gaussian, rgba(0, 0, 0, 0.5), 6, 0.5, 0, 2);
-fx-min-width: 220px;
-fx-max-width: 260px;
-fx-text-fill: white;
}
.song-title {
-fx-font-size: 14px;
-fx-font-weight: bold;
-fx-text-fill: white;
-fx-fill: white;
}
.progress-bar {
-fx-pref-width: 150px;
-fx-pref-width: 200px;
-fx-accent: red;
}
.progress-bar > .track {
-fx-background-radius: 30;
}
.progress-bar > .bar {
-fx-background-radius: 30px;
}
.progress-text {
-fx-font-size: 11px;
-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 {

View File

@@ -13,31 +13,47 @@
}
.song-display {
-fx-background-color: rgba(30, 60, 30, 0.85);
-fx-background-radius: 10px;
-fx-padding: 8 12 8 12;
-fx-spacing: 6px;
-fx-alignment: center;
-fx-effect: dropshadow(gaussian, rgba(0, 0, 0, 0.5), 6, 0.5, 0, 2);
-fx-min-width: 220px;
-fx-max-width: 260px;
-fx-text-fill: white;
}
.song-title {
-fx-font-size: 14px;
-fx-font-weight: bold;
-fx-text-fill: white;
-fx-fill: black;
}
.progress-bar {
-fx-pref-width: 150px;
-fx-inner-background-color: black;
-fx-pref-width: 200px;
-fx-accent: red;
}
.progress-bar > .track {
-fx-background-radius: 30;
}
.progress-bar > .bar {
-fx-background-radius: 30px;
}
.progress-text {
-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 {

View File

@@ -26,6 +26,7 @@ public class AudioEventListener<T extends AudioResource, K extends AudioResource
new EventFlow()
.listen(this::handleStopMusicManager)
.listen(this::handlePlaySound)
.listen(this::handleSkipSong)
.listen(this::handleStopSound)
.listen(this::handleMusicStart)
.listen(this::handleVolumeChange)
@@ -44,6 +45,10 @@ public class AudioEventListener<T extends AudioResource, K extends AudioResource
this.soundEffectManager.play(event.fileName(), event.loop());
}
private void handleSkipSong(AudioEvents.SkipMusic event) {
this.musicManager.skip();
}
private void handleStopSound(AudioEvents.StopEffect event) {
this.soundEffectManager.stop(event.fileName());
}

View File

@@ -23,6 +23,8 @@ public class MusicManager<T extends AudioResource> implements org.toop.framework
private final List<T> resources;
private int playingIndex = 0;
private boolean playing = false;
private ScheduledExecutorService scheduler;
public MusicManager(List<T> resources) {
this.dispatcher = new JavaFXDispatcher();
@@ -69,6 +71,15 @@ public class MusicManager<T extends AudioResource> implements org.toop.framework
playCurrentTrack();
}
public void skip() {
if (backgroundMusic.isEmpty()) return;
stop();
scheduler.shutdownNow();
playingIndex = playingIndex + 1;
playing = true;
playCurrentTrack();
}
// Used in testing
void play(int index) {
if (playing) {
@@ -104,8 +115,7 @@ public class MusicManager<T extends AudioResource> implements org.toop.framework
private void setTrackRunnable(T track) {
ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
scheduler = Executors.newSingleThreadScheduledExecutor();
Runnable currentMusicTask = new Runnable() {
@Override

View File

@@ -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) */
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}. */
public record ChangeVolume(double newVolume, VolumeControl controlType) implements GenericEvent {}

View File

@@ -5,4 +5,5 @@ import org.toop.framework.resource.types.AudioResource;
public interface MusicManager<T extends AudioResource> extends AudioManager<T> {
void play();
void stop();
void skip();
}