YITechnology / YIOpenAPI

YI Open API provides mobile SDKs and reference designs for software developers and hardware makers to build cool apps and products with YI 4K Action Cameras
Other
345 stars 76 forks source link

How to download big videos ? #83

Open OlostA777 opened 5 years ago

OlostA777 commented 5 years ago

I would like to add a button in my app that can download the video just filmed. I use that code, but something is missing as it stops (it works perfectly for the little one or 2 seconds videos.

  @IBAction func onSavingBtnClicked(_ sender: Any) {
        let path = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]
         let originPath = path.appending("/\(lastFileName)")
       var test:Int = 0
      let alert = UIAlertView();
        alert.message = "Saving: \(lastFileName)";
        alert.addButton(withTitle: "Ok")
        alert.show()

        self.mCamera.downloadFile(fileName: lastFileName, destFilePath: originPath, success:
            {
                downloadTask in
                self.testLbl.text = String(describing: downloadTask.downloadedBytes)
        } , fail: {
            error in

            let alert = UIAlertView();
            alert.message = error as? String;
            alert.addButton(withTitle: "Ko")
            alert.show()
        }); 
        }
    }

Should I have to use URLSession ? But I don't really know how to use it. => I don't know how to use that:

 mCamera.urlSession(<#T##session: URLSession##URLSession#>, downloadTask: downloadTask, didWriteData: downloadTask.downloadedBytes, totalBytesWritten: downloadTask.downloadedBytes, totalBytesExpectedToWrite: downloadTask.totalBytes)
//

Thanks in advance.