0 votes

So I have a AudioStreamPlayer, that has script that iterates through a folder and pulls all the wav files and stores them in an array and then a method to play one of them at random and another to skip to the next song. When I do this in the editor it works with no issues or errors, but as soon as I export it to a runnable windows exe it fails to retrieve any of the files and shows a error of
Invalid get index '0' (on base: 'Array').
At: res://World/MusicPlayer.gdc:32

this is the code below im using

extends AudioStreamPlayer
var music_list = []

func ready():
get
allmusic()
pick
song()

func input(event):
if event.is
actionpressed("skipsong"):
pick_song()

func getallmusic():
var dir = Directory.new()
dir.open("res://Assets/Music/")
dir.listdirbegin()

while true:
    var file = dir.get_next()
    if file == "":
        #no more files
        break
    elif not file.begins_with(".") && !file.ends_with(".import"):
        music_list.append(load("res://Assets/Music/" + file))

dir.list_dir_end()

func picksong():
randomize()
var list
len = musiclist.size()
var i = randi() % (list
len - 1)
stream = musiclist[i]
print(music
list[i])
play(0)

func onMusicPlayerfinished():
pick
song()

Godot version 3.3.stable.mono
in Engine by (21 points)

2 Answers

0 votes

There are two things to check for here:

  1. Add *.ogg,*.mp3,*.wav to the non-resource export filter in the Export dialog. This ensures the audio files you're trying to load at run-time are present in the PCK file.
  2. Check the file casing in the file names. Windows is not case-sensitive but the virtual PCK filesystem (which is used in export projects) is case-sensitive. I recommend using lowercase characters only in file names to prevent problems like these from cropping up.
by (12,889 points)

if the music file name has spaces in it could that cause issues too?

Spaces should be fine, but it's best to avoid them if possible.

I'm exporting all files and it appears that all files are being called correctly

+1 vote

I had the same problem. You can go around by appending all the ".import" files into the array and getting rid of the ".import" extension when you load audiostream.

var file_name = array[0].replace(".import", "")
audio.stream = load(AUDIO_FILE_PATH + file_name)

But I have no clue why this weird thing happened. I read several articles saying that copying the project folder here and there might cause the problem, which I did.
Hope this answer hlep others who might have similar problems with other audio extensions such as ogg, and wav.

P.S. : This is my first answering a question in this community though.
Hope Godot gets more popular in the near future. : )

by (16 points)
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 Frequently asked questions and 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 [email protected] with your username.