2

I am building a PhoneGap application, which contains large audio and video files. In Android the media files should be in an expansion file to keep the application size under the Google Play 50 MB limit.

I'm currently considering two ways to play the video files:

  1. Unpack (maybe temporarily) the desired video file from expansion file to sdcard, get its URL and start the media player application. Unpacking takes some time so the user would have to wait for a few seconds depending on the size of the video.
  2. Write my own video player as PhoneGap plugin using Android's VideoView class. This way I can play directly from the expansion file without first unpacking the file and get more responsive application.

However, I wonder if there is a way to get a URL to the video files inside the expansion file? That would allow my application to add the URL to the Intent with which the user's preferred media player application is started and I would prefer this approach.

1 Answer 1

2

I found myself a way to do this through a content provider. I got a hint about the Content Provider from question android play movie inside expansion file, although in that question the URL was not used to start an external application.

We need a ContentProvider class that extends Google's APEZProvider:

public class ZipFileContentProvider extends APEZProvider {
    @Override
    public String getAuthority() {
        return "com.example.expansionexperiment.provider";
    }
}

And it needs to be added to Manifest and exported:

<provider
    android:exported="true"
    android:name="com.example.expansionexperiment.ZipFileContentProvider"
    android:authorities="com.example.expansionexperiment.provider" />

The authority in the manifest and in getAuthority() must be the same.

Now we can create a Uri to the file inside Expansion File:

// Filename inside my expansion file
String filename = "video/video.mp4";
String uriString = "content://com.example.expansionexperiment.provider" +  File.separator + filename;
Uri uri = Uri.parse(uriString);

// Start video view intent
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(uri, "video/*");
startActivity(intent);

The content provider provides now access to the zip file and the files within just with the URL.

However, PhoneGap's Media plugin does not support content providers, because if the URL does not start with http, it inserts "/sdcard/" in front of the URL. (!!!) Therefore, to play audio files through the zip content provider, you will need to write your own audio plugin.

1
  • In case anyone was wondering, this is because the File plugin cannot find the URL, even though it is there. See my neglected pull request here: github.com/agamemnus/cordova-plugin-media/commit/… ... Pasi: you no longer need to use the Media plugin if you can embed Chromium with e.g. Crosswalk and use xwalk --disable-gesture-requirement-for-media-playback in platforms/android/assets/xwalk-command-line!
    – Agamemnus
    Oct 3, 2014 at 18:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.