使用swift可以通过程序在Apple TV上播放照片吗?

时间:2019-05-10 10:31:59

标签: ios swift tvos apple-tv airplay

我想使用swift在iOS中构建一个简单的应用程序,该应用程序可以在我的应用程序中显示专辑的照片,然后单击它可以在Apple TV上播放。

我阅读了许多文档和文章,但不确定是否可以对照片进行处理。很少有人说音频/视频是可能的,但不确定照片。

至少任何链接或示例代码都会有所帮助。

谢谢

1 个答案:

答案 0 :(得分:0)

用户应通过AirPlay将其连接至控制中心的Apple TV:

erlang docs on binaries Control center

然后,您可以将Apple TV用作该应用程序的第二个屏幕。

  1. 检查应用程序是否具有外部显示屏:

    if UIScreen.screens.count > 1 {
        // External display is connected ...
    }
    
  2. 为外部窗口创建新的UIScreen:

    if let externalScreen = UIScreen.screens.last {
        externalWindow = UIWindow()
        externalWindow.screen = externalScreen
        configureExternalWindow(externalWindow)
        externalWindow.isHidden = false
    }
    
  3. 并根据需要使用它来显示相册:

    // In our Collection View selection callback
    if inSingleDisplayMode {
        photoViewController.photo = photo
        navigationController?.pushViewController(photoViewController, animated: true)
    } else {
        showOnExternalDisplay(photo)
    }
    

WWDC会议上的其他信息:

AirPlay

Adding Delight to your iOS App