I am creating an app that requires around half a gigabyte of video to be offline(it is one of the main points of the app). I know the only way to do that is to use apk expansion files. However, when i looked online, i found the documentation to be very sparse and confusing. All my videos are in wmv. I know i can't play them, so i was thinking of opening an intent to open the files, and then play them from the expansion files. So in a nutshell:
1) How do i go about making a expasion apk 2) Is it possible to play video using an intent to open the user's preferred video player, from my app? 3) If not how would i do it?
I have already tried looking online but could not find anything!
According to the documentation for APK Expansion Files it actually seems quite straight-forward to me.
From the Overview section...
Each file can be up to 2GB and it can be any format you choose, but we recommend you use a compressed file to conserve bandwidth during the download.
For example you could simply have your WMV file as an Expansion File as it is without packaging it in any way. Even though compressed files are recommended most media files are compressed anyway so there'd be little benefit to putting it into a ZIP file (for example). If you have more than one WMV file, however, then you would have to use something like a ZIP file simply as a container for them and you'd obviously need to unpack them to a suitable location before playing them.
From the File name format section it appears your file will be renamed to have its extension changed to OBB along with prefixes to donate main/patch and app version and name as follows...
[main|patch].<expansion-version>.<package-name>.obb
So, for example, if you have a package name of com.mycompany.myapp with a version of 10 your main expansion file will be renamed to...
main.10.com.mycompany.myapp.obb
NOTE: Even if your original filename is myvideo.wmv (for example), it will be named as above - that's not a path it's actually the filename.
Finally, from the Storage location section, the location will be as follows...
<shared-storage>/Android/obb/<package-name>/
Using my example filename, the actual path/filename will be...
<shared-storage>/Android/obb/com.mycompany.myapp/main.10.com.mycompany.myapp.obb
To get the <shared-storage>
location you should use getExternalStorageDirectory()
and for the <package-name>
use getPackageName()
.
Example code would be...
String extStoragePath = getExternalStorageDirectory().getAbsolutePath() + "/";
String packageName = getPackageName();
String mainExpFilename = "main.10." + packageName + ".obb";
String pathToMainExpFile = extStoragePath + "Android/obb/" + packageName + "/" + mainExpFilename;
As for playing the file with a 3rd-party video player, something like this example code should work with the above...
Uri mediaUri = Uri.parse(pathToMainExpFile);
Intent i = new Intent();
i.setAction(Intent.ACTION_VIEW);
i.setDataAndType(mediaUri, "video/*");
startActivity(i);