Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
392 views
in Technique[技术] by (71.8m points)

android - 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");
    }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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");
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...