$cordovaFile error when loading video


#1

Hi there,

I’m trying to locally store images and video’s on a Android app, by using $cordovaFile and $cordovaFileTransfer. For the images this works fine. I save them trough FileTransfer and load them from my device with File. Now I’m trying to do the same with a video, when I save the video the log gives me this message:

success message: {"isFile":true,"isDirectory":false,"name":"movie1.mp4","fullPath":"/movie1.mp4","filesystem":"<FileSystem: files>","nativeURL":"file:///data/data/com.ionicframework.tzw1sttry127880/files/movie1.mp4"}

but when i’m trying to load it, the app stops, closes and doesn’t log an error. Can someone tell me what i’m doing wrong? This is my code:

app.controller('reloadCtrl', function($scope, $timeout, $ionicPlatform, $cordovaFileTransfer, $cordovaFile, $ionicLoading, $log, $http ){
 
    $ionicPlatform.ready(function() {
        var targetPath = null;

        window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem){
            persistentFilePath = cordova.file.dataDirectory;
        }, function(){
            alert("alert!!");
        });

        $scope.saveVideoOnDevice = function(){
            var testUrl = "http://videos.contentful.com/**token**/**token**/bobDylan.mp4"
            var targetPath2 = persistentFilePath + "movie1.mp4";
            var trustHosts2 = true;
            var options = {};
            $ionicLoading.show({
                template: "loading..."
            });

            $cordovaFileTransfer.download(testUrl, targetPath2, options, trustHosts2)
                .then(
                function(result2) {
                    $ionicLoading.hide();
                    $log.info('success message: '+ JSON.stringify(result2));
                },  function(err) {
                        $ionicLoading.hide();
                        alert('fail!!!!!');
                        $log.error('Error message: '+ JSON.stringify(err));
                    },  function (progress) {
                            $timeout(function () {
                                $scope.downloadProgress = (progress.loaded / progress.total) * 100;
                            }) 
                        });
        };

        $scope.callVideo = function(){
            $cordovaFile.readAsDataURL(cordova.file.dataDirectory, "movie1.mp4")
                .then(
                    function(result){
                    $scope.lVideo = result;
                }, function(error) {
                    $log.error(error);
                });
        };
        
    });
});

Thanks !