Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing to files inside obb expansion file

I'm following all official expansion files guides, but i can't find it. I'm unable to access the contained obb file i need.

I need 6 audio files (80Mb) that i "stored" (uncompressed) in a zip file and renamed as 'main.2001.test.expansion.proj.obb' and stored in '/mnt/sdcard/Android/obb/test.expansion.proj/'

I'll try to access to the files

String mainFileName = Helpers.getExpansionAPKFileName(this,true,2001);
if(!Helpers.doesFileExist(this, mainFileName, 27959282L, false))
{
    //download
} else {
    Log.d("test_file","file exist");
}

ZipResourceFile expansionFile = APKExpansionSupport.getAPKExpansionZipFile(this,2001,2001);
if(expansionFile!=null)
{
    ZipEntryRO[] ziro = expansionFile.getAllEntries();
    for (ZipEntryRO entry : ziro) {
        Log.d("test_files_zip", "fileZip filename: "+entry.getZipFileName());
        try{
            AssetFileDescriptor ro = entry.getAssetFileDescriptor();
            Log.d("test_files_zip", "--fileZip getfiledescriptor.tostring: "+ro.getFileDescriptor().toString());
            Log.d("test_files_zip", "--fileZip createinputstring.tostring: "+ro.createInputStream().toString());

            AssetFileDescriptor assetFileDescriptor = expansionFile.getAssetFileDescriptor(entry.getZipFileName()+"/audio02.mp3");
            if(assetFileDescriptor!=null) {
                Log.d("test_files_mp3", "length: "+assetFileDescriptor.getLength()); //checking it exists
            }
        }catch (IOException e){ Log.e("test_exp","IoExcp: "+e.getMessage()); }
    }
}

In -> assetFileDescriptor = expansionFile.getAssetFileDescriptor(.....); i've tried all i figuret out and found in different places, but i was unable to take the file. Is there any way to get the file from its name if it's inside the zip?

The app should play these files in an specificorder and we don't want to unzip the files and make them ""public"".


Edited. Answer to myself

Found, it was a line i didn't understand when i firstly read it or i simply miss it.

ZipResourceFile expansionFile = APKExpansionSupport.getAPKExpansionZipFile(this,2001,2001);
if(expansionFile!=null){
        FileDescriptor fd = expansionFile.getAssetFileDescriptor("audio_01.mp3");
        //or
        InputStream is = expansionFile.getInputStream("audio_01.mp3");
    }
like image 596
Jordi Avatar asked Nov 13 '22 21:11

Jordi


1 Answers

As Aarolama Bluenk suggested, here's the answer code (repited)

Found, it was a line i didn't understand when i firstly read it or i simply miss it.

ZipResourceFile expansionFile = APKExpansionSupport.getAPKExpansionZipFile(this,2001,2001);
if(expansionFile!=null){
        FileDescriptor fd = expansionFile.getAssetFileDescriptor("audio_01.mp3");
        //or
        InputStream is = expansionFile.getInputStream("audio_01.mp3");
}
like image 193
Jordi Avatar answered Nov 15 '22 12:11

Jordi