Issue playing slow-mo AVAsset in AVPlayer

后端 未结 3 1317
滥情空心
滥情空心 2020-12-18 09:09

I\'m trying to play an slow motion video (filmed by the user\'s iPhone) in an AVPlayer.

I am retrieving the AVAsset with a request on a

3条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-18 09:38

    Playing Slo-mo & Library Video in Swift 4 n above with Custom View

    var vcPlayer = AVPlayerViewController()
    var player = AVPlayer()
    
    func playallVideo(_ customView: UIView, asset: PHAsset) {
            guard asset.mediaType == .video
                else {
                    print("Not a valid video media type")
                    return
            }
            let options = PHVideoRequestOptions()
            options.isNetworkAccessAllowed = true
            PHCachingImageManager().requestPlayerItem(forVideo: asset, options: options) { (playerItem, info) in
                DispatchQueue.main.async {
                    self.player = AVPlayer(playerItem: playerItem)
                    self.vcPlayer.player = self.player
                    self.vcPlayer.view.frame = customView.bounds
                    self.vcPlayer.videoGravity = .resizeAspectFill
                    self.vcPlayer.showsPlaybackControls = true
                    //self.vcPlayer.allowsPictureInPicturePlayback = true
                    self.playerView.addSubview(self.vcPlayer.view)
                    self.player.play()
                }
            }
        }
    
    /**********Function Call ********/
    
    self.playallVideo(self.playerView/*YourCustomView*/, asset: currentAssetArr[currentIndex]/*Current PHAsset Fetched from Library*/)
    

    :) enjoy

提交回复
热议问题