ios - 使用本地 url 通过 iOS 应用程序进行 ChromeCast 视频(错误)

标签 ios arrays swift chromecast google-cast

我正在尝试使用 Chromecast 播放我的本地 url 视频。我不熟悉如何实现,下面是尝试过的代码, 我找不到太多库来使用本地 url 执行 Chromecast 并通过远程控制手机(播放/停止)来播放视频。如果有人知道可以指导好的库或建议代码。请..

override func viewDidLoad() {
    super.viewDidLoad()
    let castButton = GCKUICastButton(frame: CGRect(x: 0, y: 0, width: 24, height: 24))
    castButton.tintColor = UIColor.red
    let castBarButtonItem = UIBarButtonItem(customView: castButton)
    navigationItem.rightBarButtonItem = castBarButtonItem
    Casty.shared.initialize()
    let url: String  = "https://commondatastorage.googleapis.com/gtv-videos-bucket/CastVideos/mp4/DesigningForGoogleCast.mp4"
    let subtitleURL = "https://commondatastorage.googleapis.com/gtv-videos-bucket/CastVideos/tracks/DesigningForGoogleCast-en.vtt"
    let subtitle = GCKMediaTrack(identifier: 1, contentIdentifier: subtitleURL , contentType: "text/vtt", type: GCKMediaTrackType.text, textSubtype: GCKMediaTextTrackSubtype.captions, name: "English", languageCode: "en", customData: nil)

    //this image will show up in expanded controller as well as video thumb
    let image = GCKImage(url: URL(string: "https://commondatastorage.googleapis.com/gtv-videos-bucket/CastVideos/images/780x1200/DesigningForGoogleCast-887x1200.jpg")!, width: 780, height: 1200)

    Casty.didStartSession = { _ in
        Casty.shared.loadMedia(url: self.url , subtitles: [subtitle] , activeSubtitleID: 1 , title: "Dev" , image: image)
        Casty.shared.presentExpandedController()
        Casty.shared.addMiniController(toParentViewController: self)
    }}

最佳答案

Cast 媒体播放器仅支持通过 HTTP 进行播放。因此,您需要有一个本地网络服务器,以允许播放器访问您的本地内容。

关于ios - 使用本地 url 通过 iOS 应用程序进行 ChromeCast 视频(错误),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53515828/

相关文章:

ios - 在将新界面推送到界面 Controller 上后,如何关闭由界面 Controller 组成的两个页面中不需要的页面?在 Watchkit 上

iphone - 设置位于导航/选项卡栏之间的 UIScrollView 框架

ios - 桥接 header 中导入的 header 在 'Release' 构建配置中不可见,但在 'Debug' 构建配置中可见

javascript - 如何仅迭代数组中定义的索引?

ios - 为什么查询(DBAccess)第一次在 Id 属性中返回 nil?

ios - 如何从 SwiftUI 的详细信息 View (编辑项目 View )中删除核心数据条目?

ios - 自动调整 UITextView IOS7

python - 预期的二维数组错误未得到解决

arrays - 如何在Kotlin中查找哪个元素无法在数组之间进行比较?

swift - Swift 应用程序配色方案实现的最佳实践