如何在iOS中使用AirPlay进行屏幕镜像(不是来自控制面板)?
我正在使用MPVolumeView
来显示AirPlay
button。 我需要通过audio镜像来向Apple
TV
显示自定义壁纸。 audio在Apple
TV
上正常TV
但壁纸图像未显示。 我正在使用AVAudioController
播放audio。 我已经从video播放应用程序中检查了屏幕镜像正在工作的YouTube
应用程序。 是否有可能使用AVAudioController
在应用程序中筛选镜像?
帮我解决这个问题。 提前致谢。
不幸的是,当您在控制面板中启用AirPlay镜像时,与AirPlay相关联的外部显示器将只会变为活动状态(并发出适当的通知)。 似乎没有办法以编程方式启用镜像 。
MPVolumeView可以帮助用户将audioredirect到AirPlay扬声器,这与显示镜像无关。
你可以在这里find文档: https : //developer.apple.com/library/ios/documentation/WindowsViews/Conceptual/WindowAndScreenGuide/UsingExternalDisplay/UsingExternalDisplay.html
基本上它是关于创build第二个UIWindow
,如果外部显示器可用。 在那里,你可以展示你的壁纸,我认为这是一个图像。 应该很简单,通过一个UIImageView
到第二个UIWindow
。
您可以使用AVPlayer属性在应用程序中筛选镜像。
那个属性是
@property (nonatomic) BOOL usesAirPlayVideoWhileAirPlayScreenIsActive NS_DEPRECATED_IOS(5_0, 6_0);
要么
@property (nonatomic) BOOL usesExternalPlaybackWhileExternalScreenIsActive NS_AVAILABLE_IOS(6_0);.
usesAirPlayVideoWhileAirPlayScreenIsActive
和usesExternalPlaybackWhileExternalScreenIsActive
的默认值为NO。
如果allowsAirPlayVideo
为NO,则使用allowsAirPlayVideo
。
如果allowsExternalPlayback
是NO,那么allowsExternalPlayback
是没有效果的。
您将需要听取屏幕连接/断开通知:
NSNotificationCenter *center = [NSNotificationCenter defaultCenter]; [center addObserver:self selector:@selector(handleScreenDidConnectNotification:) name:UIScreenDidConnectNotification object:nil]; [center addObserver:self selector:@selector(handleScreenDidDisconnectNotification:) name:UIScreenDidDisconnectNotification object:nil];
在名称:UIScreenDidConnectNotification中,您将看到您的设备现在有2个屏幕,您可以进行设置。