0

Sound doesn't play when running my app in android, so suggested workarounds include AssetManager to preload files: I want to preload all files when class is initialized and play it later in a sub-function.

The manager should be globally used in the class, but it seems the definition is not the problem (tried local implementation, same error).

Here is the code:

public AssetManager manager=new AssetManager();

public InterpreterAudioPlugin() {
    //Preload all sounds
    FileHandle sounds=Gdx.files.internal("Sound");
    for (FileHandle file: sounds.list()){
        manager.load(Gdx.files.internal(file.toString()),Music.class);
        manager.finishLoading();
    }

It pops an error at load saying "no suitable method found for load". Not sure what "no suitable method" means here, since googling it revealed it is very specific to the function after, in my case "load". Any help?

khelwood
  • 55,782
  • 14
  • 81
  • 108
André
  • 142
  • 1
  • 15

1 Answers1

0

It doesn't exist a method load() which takes the Arguments: FileHandle and Class. Possible load methods are:

load(AssetDescriptor)
load(String, Class)
load(String, Class, AssetLoaderParameters)

Your first argument must be a String and not a FileHandle.

Try this:

FileHandle sounds=Gdx.files.internal("Sound");
for (FileHandle file: sounds.list()){
    manager.load("Sound/" + file.name(), Music.class);
}
manager.finishLoading();
Morchul
  • 1,987
  • 1
  • 7
  • 21
  • Omg, you're right, it took the path String directly and "Gdx.files.internal" was completely unnecessary (copy/paste from the previous load). Works like a charm now, thanks! – André Jun 17 '19 at 08:33