Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android: can't play any sound in an external vox package in single game launcher #1577

Closed
ericoporto opened this issue Mar 15, 2022 · 3 comments · Fixed by #1578
Closed

Android: can't play any sound in an external vox package in single game launcher #1577

ericoporto opened this issue Mar 15, 2022 · 3 comments · Fixed by #1578
Labels
context: game files related to the files that game uses at runtime system: android type: bug unexpected/erroneous behavior in the existing functionality
Milestone

Comments

@ericoporto
Copy link
Member

ericoporto commented Mar 15, 2022

Describe the bug
Sounds not in the game main .ags package can't be played. Because speech is always packaged as speech.vox, we can't play any speech. First reported here: https://www.adventuregamestudio.co.uk/forums/index.php?topic=59772.msg636644240#msg636644240

AGS Version
AGS 3.6.0.20 but also current master https://github.com/adventuregamestudio/ags/tree/b8a811f9e939328987af3adbbad7c72617dfbafd

To Reproduce
In the editor create a new game

  1. add any sound and make sure that it's marked to be in a .vox package instead of being packaged inside the game
  2. build for Android in the Editor
  3. verify the sound doesn't play

Expected behavior
The sound should play

Desktop:

  • OS: Windows
  • Version: 10

Smartphone:

  • Device: Pixel 2 A
  • OS: Android 11
  • Emulated

Additional context
When listing the libraries in AssetManager _activeLibs, I can only see the root dir and the game.ags file - the vox package doesn't appear as a library. I can see the game tries to look for the "/au000004.mp3" clip but it can't find it in either the ags game or in the root dir. The vox packages apparently can't be found.

In the single game package the files are not in a regular directory, and instead are accessible through the AAssetManager from Android. It appears some logic is missing for the vox packages there, but I am not sure what it's yet.

@ericoporto
Copy link
Member Author

ericoporto commented Mar 15, 2022

ok, the problem is that when searching for assets (like "./speech.vox"), it will append ./ to the file name when looking for files in the local directory, but the AAssetManager can't recognize filenames that have this at the beginning. Here is a quick fix for this:

diff --git a/Common/util/file.cpp b/Common/util/file.cpp
index f2759030a..2c09f43fe 100644
--- a/Common/util/file.cpp
+++ b/Common/util/file.cpp
@@ -218,8 +218,12 @@ Stream *File::OpenFile(const String &filename, FileOpenMode open_mode, FileWorkM
         fs = nullptr;
 #if AGS_PLATFORM_OS_ANDROID
         try {
-            if (work_mode == kFile_Read) // look into Android Assets too
-                fs = new AAssetStream(filename, AASSET_MODE_RANDOM);
+            if (work_mode == kFile_Read) { // look into Android Assets too
+                String filename_right = filename;
+                if (filename.StartsWith("./"))
+                    filename_right = filename.Right(filename.GetLength() - 2);
+                fs = new AAssetStream(filename_right, AASSET_MODE_RANDOM);
+            }
             if (fs != nullptr && !fs->IsValid()) {
                 delete fs;
                 fs = nullptr;

I don't know yet which is pretty fix for this, but I guess something just like it in the AAssetStream class would fix it.

@ivan-mogilko
Copy link
Contributor

ivan-mogilko commented Mar 15, 2022

if (filename.StartsWith("./"))
    filename_right = filename.Right(filename.GetLength() - 2);

This is probably equivalent to

filename = Path::GetFilename(filename);

@ivan-mogilko ivan-mogilko added type: bug unexpected/erroneous behavior in the existing functionality system: android context: game files related to the files that game uses at runtime labels Mar 15, 2022
@ericoporto
Copy link
Member Author

ericoporto commented Mar 15, 2022

not exactly, the asset can have directories inside it, I think

https://developer.android.com/reference/android/content/res/AssetManager#list(java.lang.String)

I am not sure if we support it or not, but I think so. It just need the ./ clipped so it's referenced at it's root - maybe this could be added to Path lib though, not sure...

it's an addition to this:

if(!asset_name.IsNullOrSpace() && asset_name[0] == '/') {
String aname = asset_name;
aname.ClipLeft(1);
_aAsset = AAssetManager_open(aAssetManager, aname.GetCStr(), asset_mode);
}

But the filenames here also needs it: https://github.com/adventuregamestudio/ags/blob/master/Common/util/android_file.cpp

Basically, if it's inside the Android Asset with AAssetManager, drop / and ./ at the beginning of every file path.

I was thinking about creating a Path::GetForeignAssetPath(String filename), I imagine other rom like proprietary packaging formats may have similar issues to the one in Android asset.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
context: game files related to the files that game uses at runtime system: android type: bug unexpected/erroneous behavior in the existing functionality
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants