gpt4 book ai didi

swift - NSNotificationCenter 到 AVQueuePlayer swift

转载 作者:搜寻专家 更新时间:2023-11-01 05:37:02 25 4
gpt4 key购买 nike

我将 AVQueuePlayer 列表添加到 UITableViewCell。我将视频数组添加到 AVQueuePlayer,如下所示:

if let urls   = delegate.arrayVideofeedItemsList[indexPath.row] as? NSArray
{
let player = AVQueuePlayer()

for currentVideoObject in urls {

let avAsset = AVURLAsset(URL: NSURL(fileURLWithPath: "\(currentVideoObject)"))

avAsset.loadValuesAsynchronouslyForKeys(["playable", "tracks", "duration"], completionHandler: {
dispatch_async(dispatch_get_main_queue(), {
// self.enqueue(avAsset)
let item = AVPlayerItem(asset: avAsset)
player.insertItem(item, afterItem: nil)
})
})
}

let playerLayer = AVPlayerLayer(player: player)
// playerLayer.backgroundColor = UIColor.greenColor().CGColor
playerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
playerLayer.frame = CGRectMake(0, 0,SCREEN_WIDTH, 250)

cell.contentView.layer.addSublayer(playerLayer)
player.play()
player.actionAtItemEnd = AVPlayerActionAtItemEnd.Advance
player.volume = 0.0

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

}

func playerItemDidReachEnd(notification: NSNotification) {
let p: AVPlayerItem = notification.object as! AVPlayerItem
p.seekToTime(kCMTimeZero)
}

我在 AVQueuePlayer 中有三个视频。三个视频按顺序播放,但第一个视频播放完成后不播放。我需要添加什么?请帮我完成它。

最佳答案

尝试在初始化播放器后添加这一行:

player.actionAtItemEnd = AVPlayerActionAtItemEnd.None

关于swift - NSNotificationCenter 到 AVQueuePlayer swift ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35940908/

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