How to do screen mirroring using AirPlay from the application (not from control panel) in iOS?

穿精又带淫゛_ 提交于 2019-11-30 16:41:10

问题


I am using MPVolumeView to show AirPlay button. I need to show a custom wallpaper to Apple TV through mirroring with audio. Audio is playing properly on Apple TV but wallpaper image is not showing. I am using AVAudioController for playing audio. I have checked YouTube application in which screen mirroring is working from application for video playing. Is it possible to screen mirroring within the app using AVAudioController ?

Help me to solve this issue. Thanks in advance.


回答1:


Unfortunately, external display associated with AirPlay will only become active (and post appropriate notification) when you enable AirPlay mirroring in control panel. There appears to be no way to enable mirroring programmatically.

MPVolumeView can help user redirect audio to AirPlay speakers, it has nothing to do with display mirroring.




回答2:


You can find the documentation here: https://developer.apple.com/library/ios/documentation/WindowsViews/Conceptual/WindowAndScreenGuide/UsingExternalDisplay/UsingExternalDisplay.html

Basically it's about creating a 2nd UIWindow, if an external display is available. There you can show your wallpaper, which is an image, I assume. Should be simple to put that via an UIImageView into that 2nd UIWindow.




回答3:


You can screen mirroring within the app using AVPlayer property.

That property is

@property (nonatomic) BOOL usesAirPlayVideoWhileAirPlayScreenIsActive NS_DEPRECATED_IOS(5_0, 6_0);

or

@property (nonatomic) BOOL usesExternalPlaybackWhileExternalScreenIsActive NS_AVAILABLE_IOS(6_0);.

The default value of usesAirPlayVideoWhileAirPlayScreenIsActive and usesExternalPlaybackWhileExternalScreenIsActive is NO.

usesAirPlayVideoWhileAirPlayScreenIsActive is no effect if allowsAirPlayVideo is NO.

And usesExternalPlaybackWhileExternalScreenIsActive is no effiect if allowsExternalPlayback is NO.




回答4:


You will need to listen for the screen connection/disconnection notifications:

NSNotificationCenter *center = [NSNotificationCenter defaultCenter];

[center addObserver:self selector:@selector(handleScreenDidConnectNotification:)
               name:UIScreenDidConnectNotification object:nil];
[center addObserver:self selector:@selector(handleScreenDidDisconnectNotification:)
               name:UIScreenDidDisconnectNotification object:nil];

In the name:UIScreenDidConnectNotification you will see that your device now has 2 screens and you can do your setup.



来源:https://stackoverflow.com/questions/23356127/how-to-do-screen-mirroring-using-airplay-from-the-application-not-from-control

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!