关于这个问题,我已经看了很多,但我发现的所有问题都已经过时了。
this article is from 2012 and says that it's not possible
基本上,我希望能够在我的应用程序中通过 airplay 将我的 iPhone 镜像到另一个屏幕,我想知道现在是否可行。我找到的文章都说这是不可能的,或者如果完成了,该应用程序将不会被应用程序商店接受。
最佳答案
从 iOS 11 开始,可以实现自己的 AirPlay 选择器 View 。请查看 AVRoutePickerView .它将允许您在应用程序内控制与不同 AppleTV/外部屏幕的连接。参见示例:
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
AVRoutePickerView *routePickerView = [[AVRoutePickerView alloc] initWithFrame:CGRectMake(0.0f, 30.0f, 30.0f, 30.0f)];
routePickerView.backgroundColor = [UIColor lightGrayColor];
[self.view addSubview:routePickerView];
AVAsset *asset = [AVAsset assetWithURL:[NSURL URLWithString:@"https://bitdash-a.akamaihd.net/content/MI201109210084_1/m3u8s/f08e80da-bf1d-4e3d-8899-f0f6155f6efa.m3u8"]];
AVPlayerItem *playerItem = [[AVPlayerItem alloc] initWithAsset:asset];
AVPlayer *player = [AVPlayer playerWithPlayerItem:playerItem];
AVPlayerLayer *playerLayer = [AVPlayerLayer playerLayerWithPlayer:player];
[playerLayer setFrame:CGRectMake(0.0f, 40.0f, self.view.frame.size.width, self.view.frame.size.height - 40.0f)];
[self.view.layer addSublayer:playerLayer];
[player seekToTime:kCMTimeZero];
[player play];
}
@end
结果是按下 AVRoutePickerView 你会得到这样的东西:
通过按下可用的外部屏幕,您将能够在其上播放内容。
关于ios - 是否可以以编程方式启用 airplay 镜像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38045488/