I would like to download files directly from the OBB extension file using AssetManager. I implemented my own FileHandleResolver
public class CustomFileHandleResolver implements FileHandleResolver { @Override public FileHandle resolve(String fileName) { return new CustomFileHandle(fileName); } }
I installed it in my AssetManager. I created my own FileHandle and I override the read () function
@Override public InputStream read() { InputStream input = null; try { input = GameInfo.expansionFile.getInputStream(file.getPath().replace('\\', '/')); } catch (IOException e) { e.printStackTrace(); } return input; }
It downloads all files, such as .PNG, .PACK, .FNT, except for .OGG files, so I think that all sound files will not be downloaded. I get this error:
com.badlogic.gdx.utils.GdxRuntimeException: com.badlogic.gdx.utils.GdxRuntimeException: Couldn't load dependencies of asset: SFx/button_click.ogg
And this error:
com.badlogic.gdx.utils.GdxRuntimeException: java.lang.ClassCastException: com.solidgamesstudio.threedefendersn.framework.CustomFileHandle cannot be cast to com.badlogic.gdx.backends.android.AndroidFileHandle
I read that zip cannot be compressed. In 7zip, I chose compression for the "Store" so that it doesn't compress at all, but still this problem arises.
I went through what happens when files are loaded, and I found that AssetManager calls my CustomFileHandleResolver , which creates a CustomFileHandle . For each file that is not .OGG, it calls InputStream read() . In this function, it loads a file from a zip code, and thatβs fine. But, as I said, when it comes to downloading .OGG, this does not call this function. Therefore, he does not even try to get the file from the zip code. The question is why the .OGG file does not call InputStream read() in CustomFileHandle() ?
UPDATE
I went through more and I found out that he will not call InputStream read() , because he somehow cannot create sound from FileHandle. The hint for this is
CustomFileHandle cannot be cast to AndroidFileHandle
For now, to create sound, you need to transfer the Handle file.
public Sound newSound (FileHandle fileHandle);
This is called from SoundLoader
@Override public void loadAsync (AssetManager manager, String fileName, FileHandle file, SoundParameter parameter) { sound = Gdx.audio.newSound(file); }
And this soundLoader uses my CustomFileHandleResolver. I do not know if sounds are processed differently than other types of files. But by default, AssetManager uses
public class InternalFileHandleResolver implements FileHandleResolver { @Override public FileHandle resolve (String fileName) { return Gdx.files.internal(fileName); } }
I can not get into Gdx.files.internal to see if there is any special processing for Sounds.
UPDATE
Further analysis makes me realize that the main problem is what was mentioned earlier.
CustomFileHandle cannot be cast to AndroidFileHandle
I do not know why it changes FileHandle to AndroidFileHandle when loading an OGG file. If it downloads files of another different type, this probably means that they are not casting for them. This means that OGG is special and needs casting. Any clues?