0

following this thread, i tried to recreate the function he used to compress a video, but I got this as a result:

This application is modifying the autolayout engine from a background thread, which can lead to engine corruption and weird crashes. This will cause an exception in a future release.

here's my code:

let video = info[UIImagePickerControllerMediaURL] as! NSURL!
let uploadURL = NSURL(fileURLWithPath: NSTemporaryDirectory()).URLByAppendingPathComponent("\(NSDate())").URLByAppendingPathComponent(".mov")

                compressVideo(video, outputURL: uploadURL, handler: { (handler) -> Void in
                    if handler.status == AVAssetExportSessionStatus.Completed
                    {
                        let data = NSData(contentsOfURL: uploadURL)

                        print("File size after compression: \(Double(data!.length / 1048576)) mb")

                        self.dismissViewControllerAnimated(true, completion: nil)


                    }

                    else if handler.status == AVAssetExportSessionStatus.Failed {
                        let alert = UIAlertView(title: "Uh oh", message: " There was a problem compressing the video maybe you can try again later. Error: \(handler.error!.localizedDescription)", delegate: nil, cancelButtonTitle: "Okay")
                        alert.show()
                    }
                })



    func compressVideo(inputURL: NSURL, outputURL: NSURL, handler:(session: AVAssetExportSession) -> Void)
{
    let urlAsset = AVURLAsset(URL: inputURL, options: nil)

    let exportSession = AVAssetExportSession(asset: urlAsset, presetName: AVAssetExportPresetMediumQuality)

    exportSession!.outputURL = outputURL

    exportSession!.outputFileType = AVFileTypeQuickTimeMovie

    exportSession!.shouldOptimizeForNetworkUse = true

    exportSession!.exportAsynchronouslyWithCompletionHandler { () -> Void in

        handler(session: exportSession!)
    }

}
Community
  • 1
  • 1
Jay
  • 2,431
  • 1
  • 14
  • 26
  • Queue? i'm callling the function within the imagePickerController did FinishPickingMediaWithInfo – Jay Mar 21 '16 at 08:40
  • can you comment this line and try once again // print("File size after compression: \(Double(data!.length / 1048576)) mb")? – Anish Parajuli 웃 Mar 21 '16 at 08:58

0 Answers0