add radio
This commit is contained in:
32
core/radio/radio.gd
Normal file
32
core/radio/radio.gd
Normal file
@@ -0,0 +1,32 @@
|
||||
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():
|
||||
push_warning("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
|
||||
Reference in New Issue
Block a user