当使用Camera API直接捕获视频时,startActivityForResult(...)没有调用

时间:2015-01-13 07:09:14

标签: android cordova android-camera

我想使用android提供的Camera API直接捕获视频。这是我的开始视频方法:

private void startVideo() {
    if (isRecording) {
         // stop recording and release camera
         mMediaRecorder.stop();  // stop the recording
         releaseMediaRecorder(); // release the MediaRecorder object
         mCamera.lock();         // take camera access back from MediaRecorder
         isRecording = false;

         // Issue is here
         Intent intent = new Intent();            
         cordova.getActivity().setResult(Activity.RESULT_OK);
         cordova.startActivityForResult(this, intent, CAMERA_PIC_REQUEST);
     } else {
         // initialize video camera
         if (prepareVideoRecorder()) {
             // Camera is available and unlocked, MediaRecorder is prepared,
             // now you can start recording
             mMediaRecorder.start();

             isRecording = true;
         } else {
             // prepare didn't work, release the camera
             releaseCamera();
             releaseMediaRecorder();
             // inform user
         }
     }
}

我的onActivityResult方法如下:

 public void onActivityResult(int requestCode, int resultCode, final Intent intent) {
    super.onActivityResult(requestCode, resultCode, intent);

    Log.i(LOG_TAG, "Inside onActivityResult...");
    if (resultCode == Activity.RESULT_OK) 
    {
        if (requestCode == CAMERA_PIC_REQUEST) 
        {               
            Runnable captureVideo = new Runnable() {

                @Override
                public void run() {

                    Uri data = null;

                    if (intent != null){
                        // Get the uri of the video clip
                        data = intent.getData();
                    }

                    if( data == null){
                       File movie = new File(getTempDirectoryPath(), "Capture.avi");
                       data = Uri.fromFile(movie);
                    }

                    // create a file object from the uri
                    if(data == null)
                    {
                        fail(createErrorObject(CAPTURE_NO_MEDIA_FILES, "Error: data is null"));
                    }
                    else
                    {
                        results.put(createMediaFile(data));

                        if (results.length() >= limit) {
                            // Send Uri back to JavaScript for viewing video
                            callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, results));
                        } else {
                            // still need to capture more video clips
                            captureVideo(duration);
                        }
                    }
                }
            };

            this.cordova.getThreadPool().execute(captureVideo);
        }
    }

}

有没有办法调用onActivitResult方法。请帮帮我。

注意:我正在使用带有Cordova插件的自定义相机API。

0 个答案:

没有答案