从iOS设备-Swift

时间:2018-09-14 15:01:50

标签: ios swift chromecast google-cast

我需要将图像从iOS应用程序投射到Chromecast。我成功投射了视频,如以下示例应用程序中所述:https://github.com/googlecast/CastVideos-ios。但是,当我尝试进行更改以发送图像时,电视将开始加载,并且从不显示图像(但有时会显示来自元数据的文本)。我究竟做错了什么?

这是我的代码:

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        let castButton = GCKUICastButton(frame: CGRect(x: 100, y: 100, width: 40, height: 40))
        castButton.tintColor = UIColor.purple
        view.addSubview(castButton)
        let sessionManager = GCKCastContext.sharedInstance().sessionManager
        sessionManager.add(self)
    }
    func buildMediaInformation() -> GCKMediaInformation {    
        let metadata = GCKMediaMetadata(metadataType: .photo)
        metadata.setString("Test Title", forKey: kGCKMetadataKeyTitle)
        let mediaInfo = GCKMediaInformation(contentID: "https://www.iconsdb.com/icons/preview/brown/circle-outline-xxl.png",
                                        streamType: .none,
                                        contentType: "image/png",
                                        metadata: metadata,
                                        adBreaks: nil,
                                        adBreakClips: nil,
                                        streamDuration: 0,
                                        mediaTracks: nil,
                                        textTrackStyle: nil,
                                        customData: nil)
        return mediaInfo
    }
    func playSelectedItemRemotely() {
        let castSession = GCKCastContext.sharedInstance().sessionManager.currentCastSession
        if castSession != nil {
        castSession?.remoteMediaClient?.loadMedia(self.buildMediaInformation())
        } else {
            print("No cast session")
        }
    }
}

extension ViewController : GCKSessionManagerListener {
    func sessionManager(_ sessionManager: GCKSessionManager, didStart session: GCKCastSession) {
        print("Session manager did start Cast Session")
        playSelectedItemRemotely()
    }
}

0 个答案:

没有答案