首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >谷歌ChromeCast iOS (Swift 3)无法播放视频

谷歌ChromeCast iOS (Swift 3)无法播放视频
EN

Stack Overflow用户
提问于 2017-04-28 04:00:32
回答 1查看 875关注 0票数 0

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

这是我的代码

这在我的OnCreate上

代码语言:javascript
运行
复制
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上

代码语言:javascript
运行
复制
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
EN

回答 1

Stack Overflow用户

发布于 2017-05-05 23:30:39

这样啊,原来是这么回事。我的问题是在Google Cast控制台上,我有一个远程接收器。需要有一个自定义风格的接收器或媒体。所以要确保你是正确的!!或者只是在你的AppID上使用一个kGCKMediaDefaultReceiverApplicationID来获取默认的use。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43666930

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档