视频捕捉不会在我的电话库中显示

时间:2016-10-24 04:47:37

标签: angularjs cordova ionic-framework cordova-media-plugin

我正在使用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。不允许修改

1 个答案:

答案 0 :(得分:1)

嗯,显然从版本4.4开始,我们无法从MICSD卡中删除和写入文件。它现在只读。。并且,当用户从库中删除文件时,该项目将无法使用。这就是我想出的。

我将视频文件复制到了cordova的外部目录,在那里我可以根据需要在需要时读取文件。所需的插件为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));
          });
      }

})