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

时间:2016-03-31 18:56:25

标签: ios iphone avplayer uiactivityindicatorview avplayerviewcontroller

我正在使用带有自定义播放控件的AVPlayerViewController实现iOS视频播放器(即showsPlaybackControls属性定义为NO)。这似乎在大多数情况下都能正常工作,我唯一看到的问题是我也想在播放器中使用自定义活动指示器,但似乎AVPlayerViewController显示默认活动指示符在某些时候缓冲视频。

有没有办法从AVPlayerViewController删除此默认活动指标视图?

图片显示我所描述的内容,底部的控件是自定义的,并覆盖在播放器顶部,但活动指示器不是。

player with custom controls and default activity indicator

2 个答案:

答案 0 :(得分:3)

我做了<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> <div ng-app="myApp" ng-controller="MyCtrl"> <table> <tr> <th>student id</th> <th>student name</th> <th>student data</th> <th>student grade</th> <th>student subject</th> <th>Add</th> <th>Remove</th> </tr> <tr ng-repeat="item in student | filter:search_query | orderBy:order_query:reverse_query"> <td>{{ item.id }}</td> <td>{{ item.name }}</td> <td>{{ item.data }}</td> <td>{{ item.grade }}</td> <td>{{ item.subject }}</td> <td><a href="javascript:void(0)" ng-click="addItem(item)">Add</a></td> <td><a href="javascript:void(0)" ng-click="removeItem(item.id)">Remove</a></td> </tr> </table> </div>的扩展,公开了内部活动指标。在这里,你带着所有Swift 3的性感:

AVPlayerViewController

有了这个,您可以轻松设置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

答案 1 :(得分:1)

我还搜索了这个解决方案,我设法制作它的方式是隐藏视频播放器视图控制器视图,一旦我开始播放视频,当视频准备播放时我再次显示它。

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
    }
}