8 Replies Latest reply on Apr 30, 2015 12:18 AM by bcd57e93-7e23-418b-a7ed-9ddb8ed95067

    Problem with caputre video android Intent

    bcd57e93-7e23-418b-a7ed-9ddb8ed95067

      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<String, Object> 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

        • Re: Problem with caputre video android Intent
          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.

            • Re: Problem with caputre video android Intent
              bcd57e93-7e23-418b-a7ed-9ddb8ed95067

              By Video capture API you mean that one or that one?

               

              The first one is not released yet if i understand and I didn't find how to make the second one works:

              - If i try to use the VideoCapture object (ruby or Javascript) i have an error of unknown object

              - If i try to include the videocapture extension in the build.yml i've got this error :

              ext - videocapture

              exception: cannot load such file -- videocapture

              rake aborted!

              Can't find extension 'videocapture'. Aborting build.

                • Re: Problem with caputre video android Intent
                  Jon Tara

                  Did you check previous answers?

                   

                  https://developer.motorolasolutions.com/search.jspa?q=video+capture

                   

                  I see you're using Ruby above, so this probably does not apply, but the VideoCapture API is not yet implemented for Javascript.

                  • Re: Problem with caputre video android Intent
                    Jon Tara

                    By Video capture API you mean that one or that one?


                    The second one needs RhoElements. I mean the first one, but not that version. Try 5.0.30.


                    Since I am currently writing a native extension, I've been watching the progress in master, because I want to follow common API best practices, and want to see how things are done in various APIs. A major effort there seems to be to get all/most of the APIs up to the new common API standard for 5.1. I don't think that code is stable at this point and is in rapid transition.


                    I recall there are some documentation issues. There is some confusion about the extension name. See the previous answers.



                      • Re: Problem with caputre video android Intent
                        bcd57e93-7e23-418b-a7ed-9ddb8ed95067

                        Hi Jon,

                         

                        I'm currently using the 5.0.30 version of rhodes but it seems that the video capture extension is only implemented for iphone platform.

                        I have check the extension sources (in rhodes/lib/extensions/videocapture/) and there's no implementation in android platform folder.

                          • Re: Problem with caputre video android Intent
                            Jon Tara

                            I think you are looking in the wrong place.

                             

                            Take a look at rhodes/lib/commonAPI/mediacapture it has Android implementation.

                             

                            Not sure why it is in two places. Maybe the one in /extensions is old cruft. Maybe the one in commonAPI is not yet used....

                            • Re: Re: Problem with caputre video android Intent
                              Jon Tara

                              Video Capture is an oddball API. It's actually part of the mediacapture API, which includes Camera and VideoCapture. You need to specify "media capture" in your build.yml extensions list, but the API is VideoCapture.

                               

                              I tried loading it and building for iOS. But the implementation for iOS is incomplete. It won't even build. There is an include of IVideocapture.h, but that file doesn't exist.

                               

                              I'm unable to build the Android version as well. I get a different error in that case.

                               

                              I think this is in flux in current master, and so perhaps we will have something that works in 5.1. It seems incomplete/not working in 5.0.30. Missing files for iOS. Broken build script for Android.

                               

                              Building mediacapture: ["/Users/jon/.rvm/gems/ruby-2.2.2@rhodes-5.0.30-sp3-57e9d466-watusi/gems/rhodes-5.0.30/lib/commonAPI/mediacapture", "rake"]
                              Build extension (arm): mediacapture
                              --------------------------------------------------------------------------------
                              PWD: /Users/jon/.rvm/gems/ruby-2.2.2@rhodes-5.0.30-sp3-57e9d466-watusi/gems/rhodes-5.0.30/lib/commonAPI/mediacapture
                              rake arch:arm -f "/Users/jon/.rvm/gems/ruby-2.2.2@rhodes-5.0.30-sp3-57e9d466-watusi/gems/rhodes-5.0.30/platform/android/build/Rakefile"
                              cd /Users/jon/.rvm/gems/ruby-2.2.2@rhodes-5.0.30-sp3-57e9d466-watusi/gems/rhodes-5.0.30/lib/commonAPI/mediacapture
                              rake aborted!
                              Don't know how to build task '/Users/jon/workspace/test5030/bin/tmp/mediacapture/arm/Videocapture.cpp.o'
                              
                              
                              Tasks: TOP => arch:arm => /Users/jon/workspace/test5030/bin/target/android/release/extensions/mediacapture/armeabi/libmediacapture.a
                              (See full trace by running task with --trace)
                              rake aborted!
                              Extension build failed: /Users/jon/.rvm/gems/ruby-2.2.2@rhodes-5.0.30-sp3-57e9d466-watusi/gems/rhodes-5.0.30/lib/commonAPI/mediacapture
                              
                              
                              
                              1 of 1 people found this helpful