Accessing to files inside obb expansion file
Asked Answered
A

1

5

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");
    }
Albright answered 28/9, 2012 at 6:57 Comment(6)
may be this asnwer will help you somehow #11716355Noctule
No, It's one of the sources i've used, but nothing about reading a file inside the obb.Albright
I tried AssetFileDescriptor fd = expansionFile.getAssetFileDescriptor(zip[0].mFileName);. but fd is null. can you help me?Bhutan
Did you try with the real file name instead of zip[0].mFileName ?Albright
If you've answered the question yourself, please add it as an answer below and mark it accepted. This will help future visitors.Dabney
when i used this code it returns an error "Not a zip archive" from ZipResourceFile.classBifarious
A
1

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");
}
Albright answered 17/3, 2013 at 18:57 Comment(1)
,I am getting an error like "Create class APKExpansionSupport". Do I need to add/download any library. Please help me.Careaga

© 2022 - 2024 — McMap. All rights reserved.