Remove Buffer Activity Indicator from AVPlayerViewController

I am implementing an iOS video player using the AVPlayerViewController with custom playback controls (i.e. the showsPlaybackControls property showsPlaybackControls defined as NO ). In most cases, this works fine, the only problem I see is that I would like to use the user action indicator with the player, but it seems that AVPlayerViewController shows the default activity indicator when buffering the video for some moments.

Is there a way to remove this default activity indicator view from the AVPlayerViewController ?

The image shows what I am describing, the controls below are normal and overlap on top of the player, but the activity indicator is not.

player with customizable controls and default activity indicator

+8
ios iphone avplayer uiactivityindicatorview avplayerviewcontroller
source share
2 answers

I made an AVPlayerViewController extension that displays an indicator of internal activity. Here you go, with all the Swift 3 sexuality:

 import AVKit extension AVPlayerViewController { /// Activity indicator contained nested inside the controller view. var activityIndicator: UIActivityIndicatorView? { // Indicator is extracted by traversing the subviews of the controller `view` property. // `AVPlayerViewController` 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 easily style the UIActivityIndicatorView or just hide it all together, for example:

 playerViewController.isActivityIndicatorHidden = true 
+2
source share

I also looked for this solution, and the way I managed to do this hides the view of the video playerโ€™s viewing controllers, as soon as I started playing the video, and when the 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 } } 
+1
source share

All Articles