playing music through script

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By godotuser111

I need to create an audiostreamplayer, add a stream, and play it through script. Any help?

:bust_in_silhouette: Reply From: njamster

The following script will add the AudioStreamPlayer-node as a child to whatever node this script is attached to, once the scene becomes ready:

func _ready():
    var music_player = = load("<PathToSoundFile>")