gpt4 book ai didi

ios - 快速视频回放持续时间长

转载 作者:行者123 更新时间:2023-11-28 08:32:16 24 4
gpt4 key购买 nike

我使用以下代码从我的库中加载视频并随后播放。我的问题是它非常慢,所以我必须等待重播大约 10 秒,即使这样它也不能正常工作。

func showVideo(obj: AnyObject!) {
manager.requestAVAssetForVideo(obj as! PHAsset, options: videoOptions, resultHandler: {(avAsset: AVAsset?, audioMix: AVAudioMix?, info: [NSObject : AnyObject]?) -> Void in
self.url = (avAsset as! AVURLAsset).URL
self.playVideo()
})
}

// plays the video
private func playVideo() {
asset = AVAsset(URL: url!)
playerItem = AVPlayerItem(asset: asset!)

player = AVPlayer(playerItem: self.playerItem!)

playerLayer = AVPlayerLayer(player: self.player)
playerLayer.frame = view.frame
view.layer.addSublayer(self.playerLayer!)

player!.play()
}

然后我从以下位置获取对象:

let allVideo = PHAsset.fetchAssetsWithMediaType(.Video, options: fetchOptions)
showVideo(allVideo.lastObject)

最佳答案

我使用通知来循环播放视频:

NSNotificationCenter.defaultCenter().addObserver(self
, selector: #selector(playerItemDidReachEnd(_:))
, name: AVPlayerItemDidPlayToEndTimeNotification
, object: player.currentItem)

和函数:

func playerItemDidReachEnd(notification: NSNotification) {
if let playerItem = notification.object {
playerItem.seekToTime(kCMTimeZero)
}
}

关于ios - 快速视频回放持续时间长,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38639018/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com