gpt4 book ai didi

ios - 带有 Swift 的 Chromecast objectForKey

转载 作者:行者123 更新时间:2023-11-28 07:13:21 25 4
gpt4 key购买 nike

我开始在 iOS 中使用 Google Cast API,并试图让它与 Apple 新编程语言 Swift 一起使用。我在 https://github.com/googlecast/CastVideos-ios 用作引用 Google 示例应用程序.问题是当它连接到转换设备并到达此处时..

func deviceManager(deviceManager: GCKDeviceManager!, didConnectToCastApplication applicationMetadata: GCKApplicationMetadata!, sessionID: String!, launchedApplication: Bool) {
NSLog("application has launched \(launchedApplication)")

mediaControlChannel = GCKMediaControlChannel.alloc()
mediaControlChannel.delegate = self
self.deviceManager.addChannel(mediaControlChannel)
mediaControlChannel.requestStatus()
NSLog("waarde van requestStatus is: \(mediaControlChannel.requestStatus())")
}

它启动并且 NSLog 给我这个“应用程序已启动:false”然后我收到以下错误.. “由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因: 'setObjectForKey: key cannot be nil'" 我查看了 Google Cast iOS 类文档,发现了这个 https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_media_metadata

然后我在那个类(class)找到了这个

- (id) objectForKey:     (NSString *)   key 
Reads the value of a field.

所以我的想法是我必须在这里放一些东西..

   @IBAction func sendVideo(sender: AnyObject) {
NSLog("Cast video")

if deviceManager == nil {
var alert = UIAlertController(title: "Not connected", message: "Please connect to Cast device", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil))
presentViewController(alert, animated: true, completion: nil)

return
}

// Define media metadata
var metaData = GCKMediaMetadata(metadataType: GCKMediaMetadataType.User)
metaData.setString("Bug Bunny!", forKey: kGCKMetadataKeyTitle)
metaData.setString("dit is allemaal maar was subtitles dasdsadhjsdfgjkkHDHSAGDH", forKey: kGCKMetadataKeySubtitle)

var url = NSURL(string: "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/images/BigBuckBunny.jpg")
metaData.addImage(GCKImage(URL: url, width: 480, height: 360))

var mediaInformation = GCKMediaInformation(contentID: "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/images/BigBuckBunny.jpg", streamType: .None, contentType: "video/mp4", metadata: metaData as GCKMediaMetadata, streamDuration: 0, customData: nil)


NSLog("waarde van mediainformation is : \(mediaInformation)")

mediaControlChannel.loadMedia(mediaInformation, autoplay: true, playPosition: 0)
}

最佳答案

作为Jesper指出,GCKMediaControlChannel.alloc() 行是错误的。

这是我知道有效的 Swift 移植 didConnectToCastApplication 方法(来自 Google CastVideos-ios 示例):

func deviceManager(deviceManager: GCKDeviceManager!, didConnectToCastApplication applicationMetadata: GCKApplicationMetadata!, sessionID: String!, launchedApplication: Bool) {

self.isReconnecting = false
self.mediaControlChannel = GCKMediaControlChannel()
self.mediaControlChannel?.delegate = self
self.receiverCommandChannel = ChromecastCommandChannel()
self.receiverCommandChannel?.delegate = self

self.deviceManager?.addChannel(self.mediaControlChannel)
self.deviceManager?.addChannel(self.receiverCommandChannel)
self.mediaControlChannel?.requestStatus()
self.receiverCommandChannel?.requestStatus()

self.applicationMetadata = applicationMetadata
self.updateCastIconButtonStates()

if let delegate = self.delegate {
if let device = self.selectedDevice {
delegate.didConnectToDevice(device)
} else {
NSLog("Can not connect to device as no selected device is set")
}
} else {
NSLog("Can not run didConnectToDevice as delegate is not set")
}

// Store sessionId in case of restart
let defaults = NSUserDefaults.standardUserDefaults()
defaults.setObject(sessionID, forKey: "lastCCSessionId")
if let deviceId = self.selectedDevice?.deviceID {
defaults.setObject(deviceId, forKey: "lastCCDeviceId")
}
defaults.synchronize()
}

关于ios - 带有 Swift 的 Chromecast objectForKey,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27529323/

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