Problem with caputre video android Intent

L Louis Mauchet 3 years 6 months ago
118 1 0

Hi,

I am facing some problems in order to capture video on android using the rhodes Intent.
I'm trying to invoke the default camera tool on the device and want to save the captured video in a file path that i pass in parameter of the Intent.
After reading some android docs, i found that kind of example :

Intent i = new Intent( android.provider.MediaStore.ACTION_VIDEO_CAPTURE );
String filePath = "/example/of/file/path.mp4";    
i.putExtra( android.provider.MediaStore.EXTRA_OUTPUT, Uri.parse(filePath) );    
startActivityForResult( i, ACTIVITY_CAPTURE_VIDEO );

So, i have implemented the rhodes equivalent which looks like :

intent_params = {  
        :action=> "android.media.action.VIDEO_CAPTURE",
        :intentType => Rho::Intent::START_ACTIVITY,
        :data => {:output =>"file:////example/of/file/path.mp4"}
     }

Rho::Intent.send(intent_params)

The camera tool is well launched but the video file is never saved in the file path i pass in parameter. I tried many different ways but the output param is always ignored.

After a deeper analysis, I found this code in the IntentSingleton.java class in the rhodes code source.

if (extras != null) {
    for (Map.Entry entry: extras.entrySet()) {
       
        if (String.class.isInstance(entry.getValue())) {
            intent.putExtra(constant(entry.getKey()), (String)entry.getValue());
        }
        else if (Boolean.class.isInstance(entry.getValue())) {
            intent.putExtra(constant(entry.getKey()), ((Boolean)entry.getValue()).booleanValue());
        }
        else if (Integer.class.isInstance(entry.getValue())) {
            intent.putExtra(constant(entry.getKey()), ((Integer)entry.getValue()).intValue());
        }
        else if (Double.class.isInstance(entry.getValue())) {
            intent.putExtra(constant(entry.getKey()), ((Double)entry.getValue()).doubleValue());
        }
        else if (ArrayList.class.isInstance(entry.getValue())) {
            ArrayList list = (ArrayList)entry.getValue();
            if ( list.size() > 0 ) {
                if (String.class.isInstance(list.get(0))) {
                    intent.putExtra(constant(entry.getKey()),list.toArray(new String[list.size()]));
                } else if (Integer.class.isInstance(list.get(0))) {
                    intent.putExtra(constant(entry.getKey()),list.toArray(new Integer[list.size()]));
                } else {
                    throw new RuntimeException("Wrong intent data: array of " + list.get(0).getClass().getName() + " is not supported as value");
                }
            } else {
                intent.putExtra(constant(entry.getKey()),new String[0]);
            }
        }
        else {
            throw new RuntimeException("Wrong intent data: " + entry.getValue().getClass().getName() + " is not supported as value");
        }
    }
}

This code is the bridge between the data we pass to the rhodes ruby Intent and the "real" android Intent.
And my problem comes from here because my output parameter is passed as a String while the Intent wants an Uri object and that's why my parameter is ignored...

I have implemented a very simple patch in order to convert my String parameter to an Uri object to fix my issue.
Is it a known issue? Would it be useful to make a pull request to fix this problem?

Louis

Please Register or Login to post a reply

1 Replies

J Jon Tara

Is there some reason you don't want to use the VideoCapture API? Is there some advantage to using an Intent?

A plus of using the VideoCapture API is that it is not limited to the Android platform.

CONTACT
Can’t find what you’re looking for?