1

我正在使用 ng-cordova 的插件捕获从手机捕获离子框架内的( https://github.com/apache/cordova-plugin-media-capture ) 视频。

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

    $cordovaCapture.captureVideo(options).then(function(videoData) {
        var i, path, len;
        for (i = 0, len = videoData.length; i < len; i += 1) {
            path = videoData[i].fullPath;
            console.log("Path of the video is = " + path.toString());
        }
    }, function(err) {
        // An error occurred. Show a message to the user
    });
}

问题是我拍摄的每一个视频都会保存到我不想要的手机图库中。如果我捕获图像,它不会保存到我手机的图库中,这正是我想要的视频捕获。有没有办法阻止视频被保存?

我尝试删除该文件,但显然视频文件未保存在 cordovafile 目录中。

function DeleteFile() {

var filename = "20161024_095758.mp4";
var relativeFilePath = "file:/storage/C8F0-1207/DCIM/Camera";
console.log('data directory: '+cordova.file.dataDirectory);
window.resolveLocalFileSystemURL(relativeFilePath, function(dir) {
dir.getFile(filename, {create:false}, function(fileEntry) {
              fileEntry.remove(function(){
                alert('file removed');
                  // The file has been removed succesfully
              },function(error){
                alert('error'+JSON.stringify(error));
                  // Error deleting the file
              },function(){
                alert('file doesnt exist');
                 // The file doesn't exist
              });
  });
});

上面删除文件的代码导致错误代码:6。不允许修改

4

1 回答 1

1

好吧,显然我们不能从 4.4 版的 MICRO SD 卡中删除和写入文件。它现在是只读的。. 而且,当用户从图库中删除文件时,该文件将无法用于项目。这是我想出的。

我将视频文件复制到了科尔多瓦的外部目录,我可以在需要时读取文件并根据需要删除。所需的插件是cordova-file-plugincordova-plugin-file-transfer

.controller('yourCtrl', function($scope,$cordovaCapture,$sce,$cordovaFile, $cordovaFileTransfer, $timeout) {
       $cordovaCapture.captureVideo(options).then(function(videoData) {
            console.log(JSON.stringify(videoData[0]));
            console.log(cordova.file.externalDataDirectory);
             $cordovaFileTransfer.download(videoData[0].fullPath, cordova.file.externalDataDirectory + 'my-video.mp4', {}, true).then(
                                function(result)
                                {
                                    console.log('success: '+ result);
                                },
                                function (error)
                                {
                                    console.log('error: '+ JSON.stringify(error));
                                },function (progress) {
                                    $timeout(function () {
                                      $scope.downloadProgress = (progress.loaded / progress.total) * 100;
                                    });
                                  },false);
               $scope.clipSrc = $sce.trustAsResourceUrl(videoData[0].fullPath);
               //$scope.videoSrc = videoData[0].fullPath;
        }, function(err) {
          alert('Err: <br />'+ JSON.stringify(videoData));
        });

  //delete the file according to filename.

    $scope.deleteVideo= function(){
        $cordovaFile.removeFile(cordova.file.externalDataDirectory, "my-video.mp4")
          .then(function (result) {
            console.log('Success: deleting videoData file' + JSON.stringify(result));
          }, function (err) {
            console.log('Error: deleting videoData file' + JSON.stringify(err));
          });
      }

})
于 2016-10-25T04:05:39.763 回答