gpt4 book ai didi

ios - Google ChromeCast iOS (Swift 3) 无法播放视频

转载 作者:行者123 更新时间:2023-11-28 15:41:24 29 4
gpt4 key购买 nike

我需要帮助!一旦我将设备连接到 chromecast,它就在即将加载时崩溃了。我不知道为什么会这样。我关注了 GoogleCast 的文档和一些示例,但似乎缺少了一些东西。你们能帮帮我吗?

这是我的代码

这是在我的 OnCreate 上

override func viewDidLoad() {
sessionManager = GCKCastContext.sharedInstance().sessionManager
sessionManager?.add(self)
castMediaController = GCKUIMediaController()

if isCastEnabled() {
playSelectedItemRemotely()
}
}

//////////////////////////////////////////////////////
// //
// Start du Google ChromeCast //
// //
//////////////////////////////////////////////////////



private func buildMediaInformation() -> GCKMediaInformation {

let metadata = GCKMediaMetadata(metadataType: GCKMediaMetadataType.generic)
metadata.setString("Title", forKey: kGCKMetadataKeyTitle)
metadata.setString("Studio", forKey: kGCKMetadataKeyStudio)

let mediaInfo = GCKMediaInformation(contentID: "streamURL",
streamType: GCKMediaStreamType.none,
contentType: "video/m3u",
metadata: metadata,
streamDuration: 60,
mediaTracks: nil,
textTrackStyle: nil,
customData: nil)
print(mediaInfo.contentID)
return mediaInfo
}


func isCastEnabled() -> Bool {
switch GCKCastContext.sharedInstance().castState {
case GCKCastState.connected:
print("cast connected")
return true
case GCKCastState.connecting:
print("cast connecting")
return true
case GCKCastState.notConnected:
print("cast notConnected")
return false
case GCKCastState.noDevicesAvailable:
print("cast noDevicesAvailable")
return false
}
}

func playSelectedItemRemotely() {

let castSession = GCKCastContext.sharedInstance().sessionManager.currentCastSession
if (castSession != nil) {
castSession?.remoteMediaClient?.loadMedia(self.buildMediaInformation(), autoplay: true)
self.dismiss(animated: true, completion: nil)
}
else {
print("no castSession!")
}
}




func sessionManager(_ sessionManager: GCKSessionManager, didStart session: GCKSession) {
playSelectedItemRemotely()
}

func sessionManager(_ sessionManager: GCKSessionManager, didResumeSession session: GCKSession) {

}

func sessionManager(_ sessionManager: GCKSessionManager, didEnd session: GCKSession, withError error: Error?) {
let castSession = GCKCastContext.sharedInstance().sessionManager.currentCastSession
castSession?.endAndStopCasting(true)
}

func sessionManager(_ sessionManager: GCKSessionManager, didFailToStart session: GCKSession, withError error: Error) {

}


override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)

// playerView.player?.replaceCurrentItem(with: nil)
//
// //this stops the session manager sending callbacks to your VideoVC
// sessionManager?.remove(self)



}

这是在我的 AppDelegate 上

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

let castAppID = "myKey"
let options = GCKCastOptions.init(receiverApplicationID: castAppID)
GCKCastContext.setSharedInstanceWith(options)
GCKLogger.sharedInstance().delegate = self

最佳答案

我明白了。我的问题出在 Google Cast Console 上,我有一个远程接收器。需要有自定义样式的接收器或媒体。所以请确保你有那个权利!或者只是在您的 AppID 上使用 kGCKMediaDefaultReceiverApplicationID 来获取默认值。

关于ios - Google ChromeCast iOS (Swift 3) 无法播放视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43666930/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com