AirPlay 支持、MPMoviePlayerController 和 MPVolumeView 关系

发布于 2024-11-02 05:34:22 字数 695 浏览 0 评论 0原文

我正在开发一个支持视频播放的 iPhone 应用程序。我正在使用 MPMoviePlayerController 和自定义控件来播放视频。为此,我将 MPMoviePlayerController 的控制样式设置为 MPMovieControlStyleNone。

我想支持正在播放的视频的 AirPlay 功能。根据文档,我们必须将 MPMoviePlayerController 的“allowsAirPlay”属性设置为 YES 才能启用 AirPlay 功能。如果我使用带有自定义控件的 MPMoviePlayerController,如何在播放器 UI 上显示 AirPlay 按钮?

我已尝试以下操作:

  1. 实例化 MPVolumeView
  2. 将 MPVolumeView 的showsRouteButton 和 shownVolumeSlider 属性设置为 NO,以隐藏音量滑块和路由按钮
  3. 在我的自定义播放器视图上添加 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:

  1. Instantiated MPVolumeView
  2. Set the showsRouteButton and showsVolumeSlider properties of MPVolumeView to NO to hide the volume slider and route button
  3. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

秋意浓 2024-11-09 05:34:22

由于 MPMoviePlayerController 只允许您一次播放一个视频,因此 MediaPlayer 框架始终知道正在播放的视频。这就是 MPVolumeView 了解 MPMoviePlayerController 的方式。我没有官方文档,但我想它是以这种方式融入框架的。

由于可能存在大量制衡(并且他们喜欢一致的 UI),Apple 只允许您使用他们的 AirPlay 按钮/UI 来利用此功能。但是,您可以将该按钮放在您想要的任何位置:

airplayButton = [[MPVolumeView alloc] init];
airplayButton.frame = CGRectMake(myX, myY, 40, 40);
[airplayButton setShowsVolumeSlider:NO];
[customPlayerControls.view addSubview:airplayButton];

我只是猜测宽度和高度为 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:

airplayButton = [[MPVolumeView alloc] init];
airplayButton.frame = CGRectMake(myX, myY, 40, 40);
[airplayButton setShowsVolumeSlider:NO];
[customPlayerControls.view addSubview:airplayButton];

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.

半仙 2024-11-09 05:34:22
for (UIButton *button in volumeView.subviews) {
if ([button isKindOfClass:[UIButton class]]) {
    [button setImage:[UIImage imageNamed:@"custom-route-button.png"] forState:UIControlStateNormal];
    [button sizeToFit];
}}

我想这会对你有帮助。

for (UIButton *button in volumeView.subviews) {
if ([button isKindOfClass:[UIButton class]]) {
    [button setImage:[UIImage imageNamed:@"custom-route-button.png"] forState:UIControlStateNormal];
    [button sizeToFit];
}}

I think this will help you.

温暖的光 2024-11-09 05:34:22

MPVolumeView 有一个属性可以隐藏音量滑块并显示“路线”按钮。因此无需遍历隐藏事物的视图。

MPVolumeView *volumeView = [[[MPVolumeView alloc] initWithFrame:myContainerView.bounds] autorelease];
volumeView.showsVolumeSlider = NO;
volumeView.showsRouteButton = YES;
[myContainerView addSubview:volumeView];

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.

MPVolumeView *volumeView = [[[MPVolumeView alloc] initWithFrame:myContainerView.bounds] autorelease];
volumeView.showsVolumeSlider = NO;
volumeView.showsRouteButton = YES;
[myContainerView addSubview:volumeView];

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.

山川志 2024-11-09 05:34:22

答案是:你不能。从 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文