Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHVideoRequestOptions' progressHandler not called

When I'm loading video from iCloud, I'd want a UIProgressView to be updated about the progress. For some reason, progressHandler doesn't get called. I've tried to do it like it's done in SamplePhotosApp (which loads images though), but can't get it working.

Here's the code I use for options and requesting the video:

    let videoRequestOptions = PHVideoRequestOptions()
    videoRequestOptions.deliveryMode = .FastFormat
    videoRequestOptions.version = .Original
    videoRequestOptions.networkAccessAllowed = true
    videoRequestOptions.progressHandler = { (progress, error, stop, info) in
        dispatch_async(dispatch_get_main_queue(), {
            print(progress)
            self.progressView.progress = Float(progress)
        })
    }

    PHImageManager.defaultManager().requestPlayerItemForVideo(asset, options: videoRequestOptions, resultHandler: {
        result, info in
        self.videoPlayer = AVPlayer(playerItem: result!)
    })

This code won't even print anything, so it looks like the progressHandler block won't be called at all. The video I'm requesting is in iCloud, because this will crash if networkAccessAllowed is set to false.

Where's the problem?

like image 660
Aleksi Sjöberg Avatar asked Mar 15 '26 12:03

Aleksi Sjöberg


1 Answers

One solution is using PHImageManager's requestAVAssetForVideo instead of requestPlayerItemForVideo. After that you can create a new AVPlayerItem with the AVAsset you got as a result. This will work with the options that were used in the question.

I think this has something to do with the way videos are stored in iCloud, because they probably aren't AVPlayerItems in iCloud. This just an educated guess, and I don't have any facts about why the other method doesn't work properly.

like image 92
Aleksi Sjöberg Avatar answered Mar 17 '26 00:03

Aleksi Sjöberg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!