Basic Audio Player with Playlist in Godot 3.4.2

Godot banner

I am leaning Godot, not so much as a video game creator but rather an easy way to make some apps. Godot is a free game development tool and engine.

I was playing around with playing audio and came up with this. I have not found too much in the way of GUI and audio beyond games so I hope this is helpful to others. This is just a working example, not a full program. I am still learning and it will likely be a lot more involved with many changes along the way. I may post all that work too. Here is the layout:

Godot Audio Example Layout
Godot Audio Example Layout

The control script is as follows (main.gd):

extends Control

# Player controls.

var audioPlayer = null
var DefaultSound = preload("res://tracks/Waves and Seagulls.wav")

func _ready():
	#get_stylebox("panel", "" ).set_texture(load("res://Assets/zenbg.png"))
	audioPlayer = AudioStreamPlayer.new()
	self.add_child(audioPlayer)
	audioPlayer.stream = DefaultSound

func _on_PlayPause_pressed():
	var button = get_node("Panel/VBoxContainer/HBoxMenu/PlayPause")
	
	if button.text == "Play":
		if audioPlayer.get_stream_paused() == false:
			audioPlayer.play()
		else:
			audioPlayer.set_stream_paused(false)
		button.text = "Pause"
	else:
		audioPlayer.set_stream_paused(true)
		button.text = "Play"

func _on_Stop_pressed():
	if audioPlayer.get_stream_paused() == true:
		audioPlayer.set_stream_paused(false)
	audioPlayer.stop()
	get_node("Panel/VBoxContainer/HBoxMenu/PlayPause").text = "Play"

func _on_ItemList_item_selected(index):
	var sound = get_node("Panel/VBoxContainer/ItemList").get_item_text(index)
	print("res://tracks/" + sound)
	DefaultSound = load("res://tracks/" + sound)
	audioPlayer.stream = DefaultSound

And the ItemList script (ItemList.gd):

extends ItemList
# Collect wav files and populate listbox. I will change these to ogg
# at some point. I also want each item to be a panel with multiple audio
# tracks, icon, and desc.

func _ready():
	get_audio_resources("res://tracks/")

func get_audio_resources(tracks_path):
	var base_dir = Directory.new()
	
	if base_dir.open(tracks_path) == OK:
		
		base_dir.list_dir_begin()
		var file_name = base_dir.get_next()
		
		while file_name:
			print("Found file: " + file_name)
			#if base_dir.current_is_dir():
				# If you need to capture directories
			#	continue # This doesn't work for some reason.
			if file_name.ends_with("wav"):
				self.add_item(file_name)
			file_name = base_dir.get_next()
	else:
		print("Unable to read resource path.")

If you want to download and review or run the project it is available here.