mrackwitz / MRProgress

Collection of iOS drop-in components to visualize progress
MIT License
2.55k stars 306 forks source link

Setting progress makes the overlay appear only when progress = 1 #134

Open tirrorex opened 7 years ago

tirrorex commented 7 years ago

Hello, trying to use MRProgress with AVAssetExportSession in swift 2.2 I want to display the overlay according the the session.progress value (going from 0 to 1). It seems however that setting the progress to the overlay does nothing until the value is equal to 1. If i did something wrong in my code could someone point me to the good direction? Here is the related code :

if let exportSession = AVAssetExportSession(asset: urlAsset, presetName: Config.VIDEO_COMPRESSION_PRESET) { exportSession.outputURL = outputURL exportSession.outputFileType = AVFileTypeMPEG4 exportSession.shouldOptimizeForNetworkUse = true exportSession.timeRange = CMTimeRangeMake(kCMTimeZero, urlAsset.duration)

        exportSession.exportAsynchronouslyWithCompletionHandler { () -> Void in
            handler(session: exportSession)
        }
        dispatch_async(dispatch_get_main_queue(), { () -> Void in
            let overlayView = MRProgressOverlayView.showOverlayAddedTo(self.view, title: "Preparing", mode: .DeterminateCircular, animated: true)
            while exportSession.status == .Waiting || exportSession.status == .Exporting {
                print("Progress: \(exportSession.progress * 100.0)%., progress \(exportSession.progress)")
                overlayView.setProgress(exportSession.progress, animated: true)
            }
            overlayView.dismiss(true)
        })
    }

output example from my print : Progress: 2.62599%., progress 0.0285576

Or it can be due to the animation delay for the overlay to appear, not sure about that.