![](/img/trans.png)
[英]Adding Activity Indicator in view of AVPlayerViewController tvos
[英]Remove buffering activity indicator from AVPlayerViewController
我做了一個AVPlayerViewController
的擴展,它公開了內部活動指示器。 在這里,所有Swift 3的性感:
import AVKit
extension AVPlayerViewController {
/// Activity indicator contained nested inside the controller's view.
var activityIndicator: UIActivityIndicatorView? {
// Indicator is extracted by traversing the subviews of the controller's `view` property.
// `AVPlayerViewController`'s view contains a private `AVLoadingIndicatorView` that
// holds an instance of `UIActivityIndicatorView` as a subview.
let nestedSubviews: [UIView] = view.subviews
.flatMap { [$0] + $0.subviews }
.flatMap { [$0] + $0.subviews }
.flatMap { [$0] + $0.subviews }
return nestedSubviews.filter { $0 is UIActivityIndicatorView }.first as? UIActivityIndicatorView
}
/// Indicating whether the built-in activity indicator is hidden or not.
var isActivityIndicatorHidden: Bool {
set {
activityIndicator?.alpha = newValue ? 0 : 1
}
get {
return activityIndicator?.alpha == 0
}
}
}
有了這個,您可以輕松地設置UIActivityIndicatorView
樣式,或者只是將它們全部隱藏起來,例如:
playerViewController.isActivityIndicatorHidden = true
我也搜索了這個解決方案,我設法制作它的方式是隱藏視頻播放器視圖控制器視圖一旦我開始播放視頻和視頻准備播放我再次顯示它。
private func playVideo() {
videoPlayer?.play()
self.addLoader()
videoPlayerController.view.hidden = true
videoPlayer?.addObserver(self, forKeyPath: "status", options: NSKeyValueObservingOptions.New, context: nil)
}
public override func observeValueForKeyPath(keyPath: String?, ofObject object: AnyObject?, change: [String : AnyObject]?, context: UnsafeMutablePointer<Void>) {
if (object?.isEqual(videoPlayer) == true && keyPath == "status") {
self.removeLoader()
videoPlayerController.view.hidden = false
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.