24 lines
678 B
GDScript
24 lines
678 B
GDScript
extends AudioStreamPlayer
|
|
|
|
@export_file("*.mp3") var track_path := ""
|
|
@export_range(-30.0, 0.0, 0.5, "suffix:dB") var playback_volume_db := -14.0
|
|
|
|
func _ready() -> void:
|
|
if track_path.is_empty():
|
|
push_error("SceneMusicPlayer has no track_path configured.")
|
|
return
|
|
|
|
var audio_data := FileAccess.get_file_as_bytes(track_path)
|
|
if audio_data.is_empty():
|
|
push_error("Could not read music track: %s" % track_path)
|
|
return
|
|
|
|
var music_stream := AudioStreamMP3.load_from_buffer(audio_data)
|
|
if music_stream == null:
|
|
push_error("Could not decode music track: %s" % track_path)
|
|
return
|
|
music_stream.loop = true
|
|
stream = music_stream
|
|
volume_db = playback_volume_db
|
|
play()
|