是否可以以编程方式启用 airplay 镜像? [英] Is it possible to enable airplay mirroring programmatically?

查看:40
本文介绍了是否可以以编程方式启用 airplay 镜像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于这个问题,我环顾四周,但我发现的所有问题都已经过时了.

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

I've looked around a lot regarding this question but all the ones I've found are pretty outdated.

example

this article is from 2012 and says that it's not possible

Basically I want to be able to start mirroring my iphone through airplay to another screen from within my app and I'm wondering if that's possible now. The articles I've found all say that it isn't possible, or if done, the app won't be accepted for the app store.

解决方案

It's possible to implement own AirPlay picker view as of iOS 11. Please check AVRoutePickerView. It'll allow you to control connections to different AppleTVs/external screens within the app. See example:

@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

As a result by pressing on AVRoutePickerView you'll get something like this:

By pressing on available external screen you'll be able to playback content on it.

这篇关于是否可以以编程方式启用 airplay 镜像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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