Using Audio Stream Player
Asked Answered
A

2

0

I'm simply trying to play a sound file, mp3, wave, whatever, that lives outside the resource folder, using a file dialog. I'm pretty certain I have the correct code. AudioStreamPlayer volume is set to 24 (max), but no sound emits. Player doesn't play. This is my code:

extends Control

# Called when the node enters the scene tree for the first time.
func _ready():
	$btnSelect.connect("pressed", self, "_on_Button_pressed")
	$FileDialog.connect("file_selected", self, "_on_FileDialog_file_selected")
	
func _on_Button_pressed():
	$FileDialog.visible = true

func _on_FileDialog_file_selected(path):
	print(path)		
	__play_stream(path)
	
func __play_stream(path):
	$AudioStreamPlayer.stream = load(path)
	$AudioStreamPlayer.play()

Seems like it should work. No error is posted. On file dialog selected I have confirmed that the correct path is returned.

Accompanyist answered 22/12, 2022 at 21:20 Comment(0)
A
0

Maybe try

func __play_stream(path):
	$AudioStreamPlayer.stream = ResourceLoader.load(path)
	$AudioStreamPlayer.play()

See more at
https://docs.godotengine.org/en/stable/classes/class_resourceloader.html
https://docs.godotengine.org/en/stable/classes/class_resourceformatloader.html

Aerobatics answered 22/12, 2022 at 22:25 Comment(0)
A
0

Aerobatics Thanks! I tried that, but no joy. Still silent as a tomb. No errors posted though.

Accompanyist answered 22/12, 2022 at 22:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.