Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the plugin in conjunction with apkfile expansion #36

Open
piermariacosina opened this issue Jun 16, 2015 · 1 comment
Open

Use the plugin in conjunction with apkfile expansion #36

piermariacosina opened this issue Jun 16, 2015 · 1 comment

Comments

@piermariacosina
Copy link

Considering that the videos are the heaviest part of the app we are considering moving them in the apk file expansion using this plugin https://github.com/agamemnus/cordova-plugin-xAPKreader

But there is a question we can't solve the file are now on res/raw they should be moved inside the file expansion, is it possible to manage it using the video plugin ?

@gylippus
Copy link

@piermariacosina I'd doubt it was the 100% recommended approach, but we have been able to do this with a bit of updating to the .java file. I'd recommend retrieving your contents name dynamically instead of hard coding it in like I did. I haven't gotten around to fixing that quite yet.

package org.apache.cordova.plugin;

import java.io.File;

import org.apache.cordova.*;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.content.Context;
import android.net.Uri;

public class Html5Video extends CordovaPlugin {
    public final String ACTION_INITIALIZE = "initialize";
    public final String ACTION_PLAY = "play";

    @Override
    public boolean execute(String action, JSONArray args, final CallbackContext callbackContext) throws JSONException {

        boolean status = false;
        Context context = cordova.getActivity();

        if (action.equals(ACTION_INITIALIZE)) {
            JSONObject videos = args.getJSONObject(0);
            JSONArray tagNames = videos.names();
            JSONObject convertedVideos = new JSONObject();

            if (tagNames != null) {
                for (int i = 0; i < tagNames.length(); i++) {
                    String[] video = videos.getString(tagNames.getString(i)).split("\\.");
                    String externalPath = toDirUrl(context.getExternalFilesDir(null));
                    //THIS WILL DEFINITELY BE DIFFERENT FOR YOU
                    convertedVideos.put(tagNames.getString(i), "content://com.test.expansion/assets/videos/" + video[0] + ".mp4");
                    LOG.d("Html5Video", "Id: " + tagNames.getString(i) + " , src: " + convertedVideos.getString(tagNames.getString(i)));
                }

                callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, convertedVideos));                
                status = true;
                convertedVideos = new JSONObject();
            }
        } else if (action.equals(ACTION_PLAY)) {
            final String videoId = args.getString(0);
            if (videoId != null) {
                cordova.getActivity().runOnUiThread(new Runnable() {
                     public void run() {
                           webView.loadUrl("javascript:window.plugins.html5Video._play(" + videoId + ")");
                     }
                });
                status = true;

                LOG.d("Html5Video", "Playing video with id: " + videoId);
            }
        }

        return status;
    }

    @Override
    public Object onMessage(String id, Object data) {
        return super.onMessage(id, data);
    }

    public String toDirUrl(File f) {
        return Uri.fromFile(f).toString() + '/';
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants