AirPlay 支持、MPMoviePlayerController 和 MPVolumeView 关系
我正在开发一个支持视频播放的 iPhone 应用程序。我正在使用 MPMoviePlayerController 和自定义控件来播放视频。为此,我将 MPMoviePlayerController 的控制样式设置为 MPMovieControlStyleNone。
我想支持正在播放的视频的 AirPlay 功能。根据文档,我们必须将 MPMoviePlayerController 的“allowsAirPlay”属性设置为 YES 才能启用 AirPlay 功能。如果我使用带有自定义控件的 MPMoviePlayerController,如何在播放器 UI 上显示 AirPlay 按钮?
我已尝试以下操作:
- 实例化 MPVolumeView
- 将 MPVolumeView 的showsRouteButton 和 shownVolumeSlider 属性设置为 NO,以隐藏音量滑块和路由按钮
- 在我的自定义播放器视图上添加 MPVolumeView
我还没有相互提供 MPVolumeView 和 MPMoviePlayerController 的引用。但是,如果 MPMoviePlayerController 的“allowsAirPlay”设置为 YES,则 AirPlay 按钮将显示在 MPVolumeView 上。 MPVolumeView 和 MPMoviePlayerController 有何关系?这两个独立创建的类之间有什么联系呢?
I am developing an iPhone application that has support for video play. I am using MPMoviePlayerController with custom controls for playing the video. For this purpose I have set control style of MPMoviePlayerController to MPMovieControlStyleNone.
I would like to support AirPlay feature for the video being played. As per the documentation, we have to set the 'allowsAirPlay' property of MPMoviePlayerController to YES to enable AirPlay feature. How can I display the AirPlay button on my player UI if I am using MPMoviePlayerController with custom controls?
I have tried the following:
- Instantiated MPVolumeView
- Set the showsRouteButton and showsVolumeSlider properties of MPVolumeView to NO to hide the volume slider and route button
- Added MPVolumeView on my custom player View
I have not given the reference of MPVolumeView and MPMoviePlayerController to each other. But, if 'allowsAirPlay' of MPMoviePlayerController is set to YES then AirPlay button gets displayed on MPVolumeView. How are MPVolumeView and MPMoviePlayerController related? What is the connection between these two classes which are created independently?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
由于 MPMoviePlayerController 只允许您一次播放一个视频,因此 MediaPlayer 框架始终知道正在播放的视频。这就是 MPVolumeView 了解 MPMoviePlayerController 的方式。我没有官方文档,但我想它是以这种方式融入框架的。
由于可能存在大量制衡(并且他们喜欢一致的 UI),Apple 只允许您使用他们的 AirPlay 按钮/UI 来利用此功能。但是,您可以将该按钮放在您想要的任何位置:
我只是猜测宽度和高度为 40,40,我确信它不正确,但是一旦我将按钮放在适当的位置,就没有关系了。
Since the MPMoviePlayerController only allows you to play one video at a time, the MediaPlayer framework always knows the video that's playing. That's how MPVolumeView knows about the MPMoviePlayerController. I have no official docs, but I imagine it's baked into the framework this way.
Since there are probably a lot of checks and balances going on (and they loves consistent UIs), Apple only allows you to use their AirPlay button/UI for tapping into this feature. You can, however, put that button wherever you want:
I just guessed on the width,height being 40,40 and I'm sure it's not correct, but once I got the button in place it didn't matter.
我想这会对你有帮助。
I think this will help you.
MPVolumeView 有一个属性可以隐藏音量滑块并显示“路线”按钮。因此无需遍历隐藏事物的视图。
AirPlay(路由)按钮的位置可能不是您所期望的,因此您可能需要稍微播放容器视图的框架才能将其放置在您想要的位置。
The MPVolumeView has an attribute to hide the volume slider and to show the Route button. So there is no need to traverse the views hiding things.
The placement of the AirPlay (Route) button may not be what you expect so you may have to play the frame of the container view a bit to get it where you want it.
答案是:你不能。从 iOS 4.3 开始,没有官方方法可以为 Airplay 提供您自己的控件 - 如果您需要该功能,则需要使用标准控件。
The answer is: you can't. There is no official method as of iOS 4.3 to provide your own controls for Airplay - you need to use the standard controls if you need that functionality.