vrp-gruppe-sechs/disco-escape-roomv-5/play_list_controller.gd

74 lines
2.2 KiB
GDScript

extends Node3D
# Referenzen
@onready var audio_player: AudioStreamPlayer3D = $AudioStreamPlayer3D
@onready var label: Label3D = $Label3D
# Playlist
var playlist: Array[AudioStream] = []
var current_index: int = 0
func _ready():
# Audio-Button verbinden
$PreviousButton.button_pressed.connect(previous_track)
$PlayPauseButton.button_pressed.connect(toggle_play_pause)
$NextButton.button_pressed.connect(next_track)
# (Optional)
# Beispiel-Playlist (ersetze mit deinen eigenen Audiodateien)
# playlist.append(preload("res://audio/song1.ogg"))
playlist.append(preload("res://music/Elektroaktivisten/Affenstillstand.wav"))
playlist.append(preload("res://music/Elektroaktivisten/Manteeno and Backlash - Vampire (Original Mix).mp3"))
playlist.append(preload("res://music/Elektroaktivisten/03-So flute.mp3"))
playlist.append(preload("res://music/Elektroaktivisten/Isman Loeschner - Domino (Derek Marin _Domina_ Remix).mp3"))
playlist.append(preload("res://music/Elektroaktivisten/Little Lu - Closing.mp3"))
playlist.append(preload("res://music/Elektroaktivisten/Lucas Türschmann - I m week remix.mp3"))
if playlist.size() > 0:
play_current_track()
else:
label.text = "Keine Songs in Playlist"
func play_current_track():
if playlist.size() == 0:
return
audio_player.stream = playlist[current_index]
audio_player.play()
update_display()
func next_track():
if playlist.size() == 0:
return
current_index = (current_index + 1) % playlist.size()
play_current_track()
func previous_track():
if playlist.size() == 0:
return
current_index = (current_index - 1 + playlist.size()) % playlist.size()
play_current_track()
func toggle_play_pause():
if audio_player.playing:
audio_player.stop()
else:
audio_player.play()
update_display()
func update_display():
var status = "" if audio_player.playing else ""
label.text = "%s Track %d/%d" % [status, current_index + 1, playlist.size()]
# Für XR Tools Pointer-Interaktion
func pointer_event(event):
if event is XRToolsPointerEvent:
if event.event_type == XRToolsPointerEvent.Type.PRESSED:
toggle_play_pause()
func _on_previous_button_button_pressed() -> void:
pass # Replace with function body.