47 lines
931 B
GDScript
47 lines
931 B
GDScript
extends AudioStreamPlayer
|
|
|
|
class_name Radio
|
|
|
|
signal track_changed(track_name: String)
|
|
|
|
|
|
@export var playlist: Array[AudioStream] = []
|
|
var current_track_index: int = 0
|
|
|
|
func _ready():
|
|
finished.connect(next_track)
|
|
#if !playlist.is_empty():
|
|
#play_track(0)
|
|
|
|
func play_track(index: int = current_track_index):
|
|
if playlist.is_empty():
|
|
return
|
|
|
|
current_track_index = posmod(index, playlist.size())
|
|
stream = playlist[current_track_index]
|
|
if stream and stream.resource_path:
|
|
track_changed.emit(stream.resource_path.get_file().get_basename().capitalize())
|
|
else:
|
|
track_changed.emit("Unknown Track")
|
|
play()
|
|
stream_paused = false
|
|
|
|
func next_track():
|
|
play_track(current_track_index + 1)
|
|
|
|
func prev_track():
|
|
play_track(current_track_index - 1)
|
|
|
|
func toggle_pause():
|
|
stream_paused = !stream_paused
|
|
|
|
func pause():
|
|
stream_paused = true
|
|
|
|
func unpause():
|
|
stream_paused = false
|
|
|
|
func stop_radio():
|
|
stop()
|
|
stream_paused = false
|