【问题标题】:Unable to get cordovaCapture to work using ngCordova on ionic无法在离子上使用 ngCordova 使 cordovaCapture 工作
【发布时间】:2016-07-08 00:22:52
【问题描述】:

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

【问题讨论】:

  • 安卓怎么样,你有没有试过在安卓上拍视频ng-click="captureVideo()"
  • @TomislavStankovic 也曾在 Android 上尝试过,但似乎不起作用。但是,相机确实有效。有什么想法吗?
  • 您在此期间是否设法解决了问题?如果您需要进一步的帮助,我在这里。

标签: javascript angularjs cordova ionic-framework ngcordova


【解决方案1】:

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

这意味着你需要同时安装两个

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

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


如果takePhoto() 有效,但captureVideo() 无效,这意味着您没有安装$cordovaCapture

【讨论】:

  • 已经安装好了。当我尝试命令时,我收到消息“插件“cordova-plugin-media-capture”已安装在 ios 上”
  • 尝试将来自$cordovaCapture的代码放入控制器内部,看看它是否有效(captureAudio、captureImage、captureVideo)。也许您将不得不删除并重新安装插件。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-10-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多