class_name AudioFile extends RefCounted ## Reads songs from files: the songs downloaded from the server, and the songs in a music ## folder. ## The file types Godot can play from a file while the game runs. const PLAYABLE_EXTENSIONS: Array[String] = ["mp3", "ogg", "wav"] ## Whether [param path] is a file type the game can play. static func is_playable(path: String) -> bool: return path.get_extension().to_lower() in PLAYABLE_EXTENSIONS ## Reads the song in [param path]. Returns null if the file is missing, is not a playable ## type, or is broken. static func load(path: String) -> AudioStream: if !FileAccess.file_exists(path): return null var stream: AudioStream = null match path.get_extension().to_lower(): "mp3": stream = AudioStreamMP3.load_from_file(path) "ogg": stream = AudioStreamOggVorbis.load_from_file(path) "wav": stream = AudioStreamWAV.load_from_file(path) if stream == null || stream.get_length() <= 0.0: return null return stream