0 votes

func onopenmusicfileselected(path):
var file = File.new()
file.open(path, File.READ)
$AudioStreamPlayer.stream = file.getcurrentfile()

##########################################

can somebody tell me what's wrong?

Godot version 3.3
in Engine by (12 points)

1 Answer

0 votes

The stream property of AudioStreamPlayer needs to be set to an AudioStream Resource, not to a file. Godot automatically loads resources with load():

$AudioStreamPlayer.stream = load("res://path/to/audio/file")
by (20,677 points)

so should I get the absolute path and

path = file.getabsolutepath()
$AudioStreamPlayer.stream = load("path")

You already have the file path. You don't need to use the File object at all.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.