如何在第二个屏幕上使用iOS 5+ AirPlay [英] How to use iOS 5+ AirPlay for a second screen

查看:212
本文介绍了如何在第二个屏幕上使用iOS 5+ AirPlay的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用iPhone 4S玩AirPlay,我遇到了一些麻烦。我已将Apple TV 2更新到最新版本(4.4.3我认为?我忘记了,它在另一个房间里,我懒得检查)我在4S上使用iOS 5.0而我使用的是Xcode 4.2 Build 4D199 。我写了一个简单的UIView应用程序,试图在可用时在第二个屏幕上绘制。这是我在viewDidLoad中的内容:

I'm toying with AirPlay using an iPhone 4S and I'm having some trouble. I've updated my Apple TV 2 to the latest (4.4.3 I think? I forget, it's in the other room and I'm too lazy to check) and I have iOS 5.0 on my 4S while I use Xcode 4.2 Build 4D199. I wrote a simple UIView app that attempts to draw on a second screen when available. Here's what I have in my viewDidLoad:

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self.view addSubview:[[MPVolumeView alloc] initWithFrame:CGRectMake(0, 0, 320, 50)]];
    NSLog(@"Registering for screen connect events...");
    // Do any additional setup after loading the view, typically from a nib.
    [[NSNotificationCenter defaultCenter]
     addObserver:self
     selector:@selector(screenDidConnect:)
     name:UIScreenDidConnectNotification
     object:nil];
    [[NSNotificationCenter defaultCenter]
     addObserver:self
     selector:@selector(screenDidDisconnect:)
     name:UIScreenDidDisconnectNotification
     object:nil];    NSLog(@"There are %i connected screens.", ScreenCount);
    if (ScreenCount > 1) {
        self.secondWindow = [self myScreenInit:[[UIScreen screens] objectAtIndex:1]];
        [self.secondWindow addSubview:[self createFullscreenViewForText:@"Second window" withSize:CGSizeMake(640, 480)]];
    }
}

当我启用TV Out时,此代码在模拟器中有效如果我在调试时启用TV Out,它总是会崩溃。我必须在模拟器的硬件菜单中启用电视输出后重新启动应用程序。重新启动时,我在第二个屏幕上看到第二个屏幕UILabel。在iPhone 4S上我只能在运行任务栏中使用AirPlay控件一直向左启用AirPlay时才能正常工作。你会注意到我在启动视图中添加了一个MPVolumeView组件,我尝试使用它来连接到我的Apple TV无济于事。

This code works in the simulator when I enable TV Out although it always crashes if I enable TV Out while in debug. I have to relaunch the app after enabling TV out in the hardware menu in the simulator. On relaunch I see the second screen UILabel on the second screen. On the iPhone 4S I can only make this work if I enable AirPlay using the AirPlay control in the running tasks bar all the way to the left. You'll note that I have added an MPVolumeView component to the view on launch which I attempt to use to connect to my Apple TV to no avail.

如果我使用in app MPVolumeView我可以成功断开Apple TV,但当我再次使用它并选择Apple TV重新连接时,我没有得到UIScreenDidConnectNotification。我唯一能看到第二个屏幕的时候是我启用镜像的时候。如果我使用AirPlay控件连接,我只计算1个屏幕并且永远不会收到通知。此外,每次启用镜像时,我都会在控制台日志中看到这一点:

If I use the in app MPVolumeView I can successfully disconnect from the Apple TV but when I use it again and select the apple TV to reconnect I do not get the UIScreenDidConnectNotification. Again the only time I can see the 2nd screen is when I enable mirroring. If I connect with either AirPlay control I only count 1 screen and never get the notification. Also, each time I enable mirroring I see this in the console logs:

Could not find mapped image ColorOnGrayShadow_AirPlay.png

这似乎已被打破,我想知道其他人在这方面的经历。当我学习新东西时,我会继续玩弄并更新这篇文章。

This seems to be broken and I would like to know what others experience has been in this area. I'll continue to toy around and update this post as I learn new things.

推荐答案

MPVolumeView的路由菜单只能控制音频流到AppleTV。
以下是您尝试执行的操作示例:
https:// github。 com / quellish / AirplayDemo /

MPVolumeView's route menu can only control an audio stream going to the AppleTV. Here's a working example of what you are trying to do: https://github.com/quellish/AirplayDemo/

对于iOS 5,ColorOnGrayShadow_AirPlay.png日志消息是正常的。使用Airplay连接AppleTV作为外部显示器不幸需要镜像,您无法从应用程序内部激活它。用户必须遵循以下说明:

The "ColorOnGrayShadow_AirPlay.png" log message is normal for iOS 5. Using an Airplay connected AppleTV as an external display unfortunately requires mirroring, and you can't activate that from inside your app. The user has to follow these instructions:

http: //support.apple.com/kb/TS4085

这篇关于如何在第二个屏幕上使用iOS 5+ AirPlay的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆