我无法使cordovaCapture.captureVideo正常工作。使用cordovaCamera可以让我使用相机拍摄照片并从媒体库中选择照片,没有任何问题,但是我试图使用cordovaCapture在iOS上拍摄视频,我也想将视频的缩略图或图像预览到拍摄视频后在视图上显示。

我在下面包含了使用cordovaCamera和cordovaCapture的代码。我已经按照ngCordova网站上的示例进行操作。

.controller("CameraController", function($scope, $cordovaCamera, $cordovaCapture) {
  $scope.takePhoto = function () {
    var options = {
      quality: 75,
      cameraDirection: Camera.Direction.FRONT,
      destinationType: Camera.DestinationType.DATA_URL,
      sourceType: Camera.PictureSourceType.CAMERA,
      allowEdit: true,
      encodingType: Camera.EncodingType.JPEG,
      popoverOptions: CameraPopoverOptions,
      saveToPhotoAlbum: false
    };

    $cordovaCamera.getPicture(options).then(function (imageData) {
        $scope.imgURI = "data:image/jpeg;base64," + imageData;
    }, function (err) {
        // An error occured. Show a message to the user
    });
  }

  $scope.choosePhoto = function () {
    var options = {
      quality: 75,
      destinationType: Camera.DestinationType.DATA_URL,
      sourceType: Camera.PictureSourceType.PHOTOLIBRARY,
      allowEdit: true,
      encodingType: Camera.EncodingType.JPEG,
      popoverOptions: CameraPopoverOptions,
      saveToPhotoAlbum: false
    };

    $cordovaCamera.getPicture(options).then(function (imageData) {
        $scope.imgURI = "data:image/jpeg;base64," + imageData;
    }, function (err) {
        // An error occured. Show a message to the user
    });
  }

  $scope.captureVideo = function() {
    var options = { limit: 1, duration: 15 };

    $cordovaCapture.captureVideo(options).then(function(videoData) {
      // Video data
    }, function(err) {
      // An error occurred. Show a message to the user
    });
  }
})

最佳答案

我看到您在控制器内部使用了$cordovaCamera$cordovaCapture

这意味着您需要同时安装

来自$cordovaCamera$ cordova plugin add cordova-plugin-camera



来自$cordovaCapture$ cordova plugin add cordova-plugin-media-capture


如果takePhoto()有效,但captureVideo()无效,则表明您没有安装$cordovaCapture

09-25 16:21