简体   繁体   English

从AVPlayerViewController中删除缓冲活动指示器

[英]Remove buffering activity indicator from AVPlayerViewController

I'm implementing an iOS video player using AVPlayerViewController with custom playback controls (ie, the showsPlaybackControls property is defined as NO ). 我正在使用带有自定义播放控件的AVPlayerViewController实现iOS视频播放器(即, showsPlaybackControls属性定义为NO )。 This seems to work properly in most cases, the only issue I'm seeing is that I would like to use a custom activity indicator with the player as well, but it seems that AVPlayerViewController shows a default activity indicator while buffering the video at some points. 这似乎在大多数情况下都能正常工作,我看到的唯一问题是我想在播放器中使用自定义活动指示器,但似乎AVPlayerViewController在某些点缓冲视频时显示默认活动指示器。

Is there a way to remove this default activity indicator view from AVPlayerViewController ? 有没有办法从AVPlayerViewController删除此默认活动指示器视图?

The image shows what I'm describing, the controls at the bottom are custom and overlaid on top of the player, but the activity indicator is not. 图像显示我正在描述的内容,底部的控件是自定义的并覆盖在播放器顶部,但活动指示器不是。

具有自定义控件和默认活动指示器的玩家

I made an extension of AVPlayerViewController that exposes the internal activity indicator. 我做了一个AVPlayerViewController的扩展,它公开了内部活动指示器。 Here you go, with all the Swift 3 sexiness: 在这里,所有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
        }
    }
}

With this, you can either easily style the UIActivityIndicatorView or just hide it all together, eg: 有了这个,您可以轻松地设置UIActivityIndicatorView样式,或者只是将它们全部隐藏起来,例如:

playerViewController.isActivityIndicatorHidden = true

I also searched for this solution and the way I managed to make it is hide video player view controllers view once I started playing video and when video is ready to play I show it again. 我也搜索了这个解决方案,我设法制作它的方式是隐藏视频播放器视图控制器视图一旦我开始播放视频和视频准备播放我再次显示它。

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.

相关问题 鉴于AVPlayerViewController tvos添加活动指示器 - Adding Activity Indicator in view of AVPlayerViewController tvos 从UIButton视图中删除活动指示器子视图 - Remove Activity Indicator subview from UIButton view 在 AVPLayerViewController 中添加活动指示器? (注意:当视频处于全屏模式时) - Add activity indicator in AVPLayerViewController ? (Note: When video is in fullscreen mode) 我想在缓冲时向我的 avplayer 添加活动指示器 - I want to add activity indicator to my avplayer when its buffering 如何从我们的视图中删除AVPlayerViewController? - How to remove AVPlayerViewController from our view? 从iOS 10中的AVPlayerViewController和MPMoviePlayerController中删除状态栏 - Remove status bar from a AVPlayerViewController and MPMoviePlayerController in iOS 10 从 UIPageViewController 中移除页面指示器 - Remove the page indicator from UIPageViewController 显示活动指示器以从UIActivityViewController共享到Facebook? - Display Activity Indicator for sharing to Facebook from UIActivityViewController? 活动指示器未从googlemap视图中删除 - Activity indicator is not being removed from googlemap view 来自应用程序委托的stopAnimating活动指示器 - stopAnimating activity indicator from app delegate
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM