无法使用ngCordova在离子上使cordovaCapture起作用

时间:2016-07-06 20:37:03

标签: javascript angularjs cordova ionic-framework ngcordova

我无法使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
    });
  }
})

1 个答案:

答案 0 :(得分:2)

我发现你在控制器中使用了$cordovaCamera$cordovaCapture

这意味着您需要同时安装

来自$cordovaCamera

$ cordova plugin add cordova-plugin-camera

来自$cordovaCapture

$ cordova plugin add cordova-plugin-media-capture

<小时/> 如果takePhoto()有效,但captureVideo()没有,则表示您未安装$cordovaCapture