【问题标题】:Is it possible to enable airplay mirroring programmatically?是否可以通过编程方式启用 Airplay 镜像?
【发布时间】:2016-06-27 03:30:31
【问题描述】:

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

example

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

基本上,我希望能够开始通过 Airplay 将我的 iphone 从我的应用程序中镜像到另一个屏幕,我想知道现在这是否可能。我找到的文章都说不可能,或者如果完成了,该应用程序将不会被应用商店接受。

【问题讨论】:

  • 目前还不可能。没有可用的公共 API。

标签: ios xcode swift mirror airplay


【解决方案1】:

从 iOS 11 开始可以实现自己的 AirPlay 选择器视图。请检查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,你会得到这样的结果:

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

【讨论】:

  • 我使用 AVRoutePickerView 构建了一个小样本,它似乎等同于 MPVolumeView,它似乎将现有的 AV 会话路由到另一个设备,但它似乎没有开始镜像非媒体内容。
  • 我可以使用 AVRoutePickerView 以编程方式触发路线选择吗?
  • 这个答案没有解决被问到的问题:OP 想要启动 Airplay programmatically,这意味着用户不应该点击屏幕上的任何东西来开始吧。
  • @Maxim,我需要将我的应用程序屏幕镜像到外部电视(屏幕),我可以通过 AVRoutePickerView 执行此操作并从列表中连接设备吗?或者你有想法这样做?我看到 Google Cast SDK(iOS) 只播放视频(媒体内容),但我需要将普通的应用程序屏幕/视图镜像到外部电视。任何人都可以回答,请!
【解决方案2】:

这仍然是不可能的。没有用于启用 AirPlay 的公共 API(并且不会提交私有 API)。这是一项系统级功能,无法通过应用进行操作。

用户必须启动 AirPlay,但您可以简单地显示一条消息,建议用户打开 AirPlay 以增强应用程序。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-31
    相关资源
    最近更新 更多