extends AudioStreamPlayer

class_name Radio

@export var playlist: Array[AudioStream] = []
var current_track_index: int = 0

func _ready():
	finished.connect(next_track)

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]
	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 stop_radio():
	stop()
	stream_paused = false
