ios - 是否可以以编程方式启用 airplay 镜像?

标签 ios xcode swift mirror airplay

关于这个问题,我已经看了很多,但我发现的所有问题都已经过时了。

example

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 你会得到这样的东西: enter image description here

通过按下可用的外部屏幕,您将能够在其上播放内容。

关于ios - 是否可以以编程方式启用 airplay 镜像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38045488/

相关文章:

ios - 如何通过 iOS Swift 3 中的交互处理 UICollectionViewCell 中的 UITableView?

ios - 如何针对随 SDK 变化的方法创建单元测试?

ios - SDK 中支持 Swift,部署目标为 7.0

iOS UITableView 默认滑动删除按钮在滑动单元格时不显示

swift - 只有特定的包标识符找不到框架错误

swift - 使用 RxTableView 在 tableView 中显示空状态标签,mvvm 架构

iphone - Objective - C 菜鸟 NSString 问题

ios - 从其中一个末端同时旋转 y,z 轴上的 View

ios - 在 Xcode 中使用带有 NSMutableArray 的过滤器函数

ios - 如何从 UICollectionViewCell 中调用 presentViewController