javaaudiolibgdxandroid-assetmanager

What's wrong with "no suitable method found for load"?


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?


Solution

  • 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();