我正在开发一款支持视频播放的iPhone应用程序。使用MPMoviePlayerController和自定义控件来播放视频。为此,我将MPMoviePlayerController的控制样式设置为MPMovieControlStyleNone。
我想要支持正在播放的视频的AirPlay功能。根据文档,我们必须将MPMoviePlayerController的'allowsAirPlay'属性设置为YES以启用AirPlay功能。如果我正在使用具有自定义控件的MPMoviePlayerController,该如何在我的播放器UI上显示AirPlay按钮?
我尝试了以下操作:
- 实例化MPVolumeView
- 将MPVolumeView的showsRouteButton和showsVolumeSlider属性设置为NO以隐藏音量滑块和路由按钮
- 将MPVolumeView添加到我的自定义播放器视图中
我没有将MPVolumeView和MPMoviePlayerController的引用彼此赋值。但是,如果将MPMoviePlayerController的'allowsAirPlay'设置为YES,则AirPlay按钮将显示在MPVolumeView上。MPVolumeView和MPMoviePlayerController之间有什么关系?这两个独立创建的类之间有什么连接?
答案: 在使用MPMoviePlayerController时,可以通过设置其'allowsAirPlay'属性为YES启用AirPlay功能。如果要在自定义播放器UI上显示AirPlay按钮,则需要将MPMoviePlayerController的视图层次结构与MPVolumeView相关联。尽管这两个类是独立创建的,但是它们之间有联系。当MPMoviePlayerController的'allowsAirPlay'属性设置为YES时,它会自动搜索其视图层次结构中的MPVolumeView,并在其上显示AirPlay按钮。因此,将MPVolumeView添加到自定义播放器视图中可以使AirPlay按钮在该视图上显示。