2

Have been trying to read the videos from my apk expansion (.obb file) but it doesn't seem to work. Have followed each steps mentioned in the official android docs. I'm using the sample-app (Sample downloader app in Android-sdk/extras/google/play_apk_expansion/downloader_sample) to test if i can read the .obb file . This is what i have done.

  1. Created the zipped file (zero-compression) out of my .mp4 video files as "videos.zip".

  2. Successfully created the .obb file using the Android 'jobb' tool.

  3. Placed the obb file (main.6.com.example.expansion.downloader.obb) in /sdcard/Android/obb/com.example.expansion.downloader/ .

  4. Created a new MediaPlayerActivity class (MediaPlayerActivity.java) where i'm trying to play a video file inside the .obb file.

    expansionFile = APKExpansionSupport.getAPKExpansionZipFile(this,
                    6, 0);     
    .....
    .....
    .....
    AssetFileDescriptor afd = expansionFile.getAssetFileDescriptor("sample1.mp4"); //nullpointerexception at this line.
    Log.i("afd: ", ""+afd); //afd is null. How come??
    

Have also tried the following (just in case)

expansionFile.getAssetFileDescriptor("videos/sample1.mp4"). But it gives the same nullpointerexception. 

Please help people.

Thanks!

Edit: I think I may have found the the source of error. But still don't know how to fix it. Actually, the expansionFile itself contains null values.

expansionFile = APKExpansionSupport.getAPKExpansionZipFile(this,
            6, 0);     
Log.i("expansionFile: ", ""+expansionFile); //--> expansionFile is null

Also, there was one more error in the logcat I might have missed out earlier :-> "Not a Zip archive" which traces its existence to the addPatchFile(zipFilename) method in ZipResourceFile.java.

int header = read4LE(f);
    if (header == kEOCDSignature) {
        Log.i(LOG_TAG, "Found Zip archive, but it looks empty");
        throw new IOException();
    } else if (header != kLFHSignature) {
        Log.v(LOG_TAG, "Not a Zip archive");
        throw new IOException();
    }

Now, when I tried tracing the method-calls, I found out that my

APKExpansionSupport.getAPKExpansionZipFile(...) in turn calls getResourceZipFile(expansionFiles) which in turn calls addPatchFile(expansionFilePath) which is where it shows a log--> "Not a zip archive" as shown above in the code-snippet. So i suppose, the .obb file is supposed to be converted to a zip file (zero compression again) which i did and renamed the obb file to "main.6.com.example.expansion.downloader.obb.zip" (and for obvious reasons. I also renamed the obb-path in the code to <...>.obb.zip). Having done all this, now the expansionFile doesn't contain null value, but still my AssetFileDescriptor afd is assigned null value. Well, obviously this approach seems flawed to me (as I think .obb file shouldn't be zipped to <..>.obb.zip. Have also tried with the same obb-file name after zipping (i.e., without any .zip extension.). It did not work either).

Please help.

P.S.: Have looked up all over the "stackoverflow" & web, but none of them helped.

epiphany27
  • 517
  • 1
  • 10
  • 23
  • 1
    As far as I understand it, an .obb file is the same as a zip file, which means that if you're running the JOBB tool on a zip file, you're double compressing. You should either zip or run the JOBB tool. Hope this helps. – Dan Smart Feb 19 '14 at 07:10

2 Answers2

1

I have had limited success using the StorageManager class to access an obb created by JOBB. I haven't tried the APKExpansionSupport class. StorageManager is built into the Android libraries.

I say limited success because most of the time onObbStateChange() doesn't get called when I mount the obb using mountObb(). However, it does appear that the obb is getting mounted. I can see it in the file system and I can call getMountedObbPath() to access it.

I also occasionally am unable to access the files within the obb. It mounts but then appears to be empty (which led me to your post). This has, at least once, fixed itself after rebuilding and downloading a new obb. I have no idea why but at the moment I once again cannot access the contents.

Doug Gerecht
  • 404
  • 4
  • 9
0

Maybe this post will help you I guess its all about ContentProvider and you can't just obtain an URI to video file inside obb zip without some additional coding. Also check this post - maybe you had missed something in the path to a file.

Community
  • 1
  • 1
Stan
  • 6,511
  • 8
  • 55
  • 87