我有一个AVPlayer
,它从远程url加载其内容。当创建AVPlayer
时,它会显示视频的缩略图。我找不到任何关于通知或属性的信息,可以监听以查看何时添加此缩略图,因为我想在添加缩略图之前显示加载屏幕,并在添加后将其删除。
class VideoView: UIView {
private var playerLayer: AVPlayerLayer {
return layer as! AVPlayerLayer
}
public var videoURL: URL? {
didSet {
guard videoURL != oldValue
else { return }
if let videoURL = videoURL {
avPlayer = AVPlayer(url: videoURL)
playerLayer.player = avPlayer
}
}
}
private var avPlayer: AVPlayer?
override public static var layerClass: AnyClass {
return AVPlayerLayer.self
}
}
我尝试观察玩家的currentItem.status
值何时为readyToPlay
,但是缩略图是在状态更改为readyToPlay
之后添加的。
observer = currentItem.observe(\.status) { [weak self] (currentItem, change) in
if currentItem.status == .readyToPlay {
self?.overlay?.isHidden = false
}
}
谢谢