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.
Created the zipped file (zero-compression) out of my .mp4 video files as "videos.zip".
Successfully created the .obb file using the Android 'jobb' tool.
Placed the obb file (main.6.com.example.expansion.downloader.obb) in /sdcard/Android/obb/com.example.expansion.downloader/ .
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.