2017-03-09 3 views
0

Ich versuche, ein Video von einer URL in meinem iOS-Gerät mit einem ionischen Cordova file transfer zu speichern.Speichern von Videodateien in iOS-Galerie mit Cordova-Plugin

var fileTransfer = new FileTransfer(); 
     var uri = "https:xyz.abc/demo.mp4"; 
     var fileURL = cordova.file.documentsDirectory + 'demoRename.mp4'; 

    fileTransfer.download(
    uri, fileURL, function (entry) { 
     console.log("download complete: " + entry.toURL()); 
    }, 
    function (error) { 
     console.log("download error source " + error.source); 
     console.log("download error target " + error.target); 
     console.log("download error code" + error.code); 
    } 
); 

Ich kann den heruntergeladenen Pfad wie folgt mit Konsolenprotokoll sehen.

[Log] download complete: file:///var/mobile/Containers/Data/Application/EB4C2F9A-9C4D-4CA6-BED0-D83B7D4CBDE1/Documents/demoRename.mp4 

Aber ich kann die heruntergeladene Videodatei in meiner Galerie oder in den Fotos nicht sehen, Wo finde ich sie oder ich es richtig mache?

Antwort

0

Sie müssen das Video in der Galerie speichern, dann können Sie das heruntergeladene Video in der Galerie sehen.

Verwenden Sie bitte das Foto-Bibliothek-Plugin und folgen Sie den nachstehenden Link.

https://github.com/terikon/cordova-plugin-photo-library

den Code unten verwenden kann, es wird hilfreich für Sie.

//based on device type choosing the location to save the video 
if (ionic.Platform.isIOS()) { 
var path = cordova.file.documentsDirectory; 
var filename = "preview.mp4"; 
} else { 
var path = cordova.file.externalRootDirectory; 
var filename = "preview" + $filter('date')(new Date(), "yyyy-MM-dd  HH:mm:ss") + ".mp4"; 
} 
//Creating directory to save video in the device 

$cordovaFile.createDir(path, "dir", true).then(function(success) { 
var targetPath = path + "dir/" + filename; 
var trustHosts = true; 
var options = {}; 
//Downloading the file from URL. 
$cordovaFileTransfer.download("video URL", targetPath, options,  trustHosts).then(function(result) { 
    //Once downloaded the file calling function to add the video to photo library 
    if (ionic.Platform.isIOS()) { 
     function savelibrery() { 
      cordova.plugins.photoLibrary.saveVideo(targetPath, album,  function(success) {}, function(err) { 
       if (err.startsWith('Permission')) { 
         cordova.plugins.photoLibrary.requestAuthorization(function() { 
          savelibrery(); 
         }, function(err) { 
          $ionicLoading.hide(); 
          $cordovaToast.show("Oops! unable to save video, please try after sometime.", "long", "center"); 
          // User denied the access 
         }, // if options not provided, defaults to {read: true}. 
         { 
          read: true, 
          write: true 
         }); 
       } 
      }); 
     } 
     savelibrery() 
    } else { 
     //add refresh media plug in for refresh the gallery for android to see the downloaded video. 
     refreshMedia.refresh(targetPath); 
    } 
    $ionicLoading.hide(); 

    $cordovaToast.show("Vidoe saved successfully", "long", "center"); 
}, function(error) { 

    $ionicLoading.hide(); 
    $cordovaToast.show("Oops! unable to save video, please try after sometime.", "long", "center"); 
}, function(progress) { 
    $scope.downloadProgress = (progress.loaded/progress.total) * 100; 
    $cordovaToast.show("In progress", "short", "center"); 
}); 
}, function(error) { 
//alert(JSON.stringify(error));     
$ionicLoading.hide(); 
$cordovaToast.show("Oops! unable to save video, please try after sometime.", "long", "center"); 
}); 
+0

Ich bekomme eine RefreshMedia ist nicht definiert. Fehle ich hier als Plugin? – MatTaNg

Verwandte Themen