2015-01-08 2 views
1

이를 만들기 위해 나는 Github에서 https://github.com/googlecast/CastHelloText-ios 다음 & https://github.com/googlecast/CastVideos-iosGoogle Cast 기기에 제대로 연결하고 맞춤 수신기로 URL을 전송하는 방법은 무엇인가요? 당신이 Google 전송과 관련이있다 코드 내 블록에서 봐 다운로드 한 경우

에서 Google 전송 기준을 사용했다. 이 오류가 발생하는 것을 발견하면 알려 주시기 바랍니다. 이 Xcode 또는 Google Cast 버그 .. 또는 가장 일반적인 오류인지 여부를 솔직하게 알지 못합니다. 인간

에뮬레이터를 시작하면 네트워크에서 활성 Chrome Cast 기기를 찾습니다. 발견되면 전송 버튼이 나타납니다. 캐스트 버튼을 누르면 기능이 chooseDevice()으로 바뀌며 네트워크에있는 장치로 UIAlertController를 표시 한 다음 전송할 장치를 선택할 수 있습니다.

장치를 클릭하면 connectToDevice() 기능으로 이동하여 연결합니다.

연결되면 "deviceManagerDidConnect"라는 다음 함수로 이동해야합니다. 그래서 나는 "Connected"라는 메시지를 얻습니다. 5 초 후에 "Error Domain = com.google.GCKError Code = 2. Network connection timeout"이라는 오류 메시지가 나타납니다. 내가 프로젝트를 다시 만들 때 나는 다른 결과를 얻는다 .. "deviceManagerDidConnect"이후에 이제는 "didConnectToCastApplication"함수로 가고 그 것이 처음에는 발생하지 않았다. 이 버그입니까 아니면 내가 잘못하고있는 거지?

내가 "deviceManagerDidConnect"로 가고 나서 "didConnectToCastApplication"기능을 수행 할 것으로 예상됩니다. 그 후 WKWebView를 캐스팅하고 싶습니다. 아직 지원되지 않았습니다. 그래서 저는 Textfield에 내가 준 URL을 캐스팅하고 싶습니다.

어떤 제품 버전을 사용하고 있습니까? 어떤 운영 체제 에서요?
GoogleCastSDK-2.5.1-출시, OS X 요세미티 10.10.1 엑스 코드 버전 6.1.1 (6A2008a)

미리 감사하고 좋은 하루 되세요,

FERI

당신이 할 수있는 아래 내 코드를 찾으십시오.

// ==================== Google Cast ==================== 
    // ==================== chooseDevice() ==================== 
func chooseDevice() { 
    if selectedDevice == nil { 
     let alertController = UIAlertController(title: "Choose device..", message: "", preferredStyle: .ActionSheet) 

     for device in deviceScanner.devices { 
      alertController.addAction(UIAlertAction(title: device.friendlyName, style: .Default, handler: { alertAction in 
       self.selectedDevice = device as GCKDevice 
       self.connectToDevice() 
      })) 
     } 

     let addCancelAction = UIAlertAction(title: "Cancel", style: .Cancel, handler: { alertAction in 
      alertController.dismissViewControllerAnimated(true, completion: nil) 
     }) 

     // Add action to the controller 
     alertController.addAction(addCancelAction) 

     // Finaly present the action controller 
     presentViewController(alertController, animated: true, completion: nil) 
    } 
    else { 
     updateButtonStates() 

     let mediaTitle = self.mediaInformation?.metadata.stringForKey(kGCKMetadataKeyTitle) 
     //   mediaTitle.metadata.stringForKey(kGCKMetadataKeyTitle) //Silver Essence Castaway 
     //   var mediaTitle = mediaInformation.metadata.stringForKey(kGCKMetadataKeyTitle) 

     NSLog("De waarde van kGCKMetadataKeyTitle is: \(kGCKMetadataKeyTitle)") 

     let alertController = UIAlertController(title: "Casting to: \(selectedDevice.friendlyName)", message: nil, preferredStyle: .ActionSheet) 

     let addDisconnectingAction = UIAlertAction(title: "Disconnect device", style: .Destructive, handler: { alertAction in 
          println("De waarde van mediaInformation is: \(mediaTitle)") 
          if mediaTitle != nil { 
           (mediaTitle != nil ? 1 : 0) 
           alertController.dismissViewControllerAnimated(true, completion: nil) 
           println("the else UIAlertController") 
          } 
     }) 

     let addCancelAction = UIAlertAction(title: "Cancel", style: .Cancel, handler: { alertAction in 
          println("De waarde van mediaInformation is: \(mediaTitle)") 
          if mediaTitle != nil { 
           (mediaTitle != nil ? 2 : 1) 
           alertController.dismissViewControllerAnimated(true, completion: nil) 
           println("else uiactionsheet") 
          } 
     }) 

     // Add action to the controller 
     alertController.addAction(addDisconnectingAction) 
     alertController.addAction(addCancelAction) 

     // Finaly present the action controller 
     self.presentViewController(alertController, animated: true, completion: nil) 
    } 
} 

    // ==================== updateStatsFromDevice() ==================== 
func updateStatsFromDevice() { 
    if mediaControlChannel != nil { 
     mediaInformation = mediaControlChannel.mediaStatus.mediaInformation 
    } 
} 

    // ==================== isConnected() ==================== 
func isConnected() -> Bool { 
    return deviceManager.isConnected 
} 

    // ==================== connectToDevice() ==================== 
func connectToDevice() { 
    if selectedDevice != nil { 
     //   var info = NSBundle.mainBundle().infoDictionary!["CFBundleIdentifier"] as? NSString 
     //   deviceManager = GCKDeviceManager(device: selectedDevice, clientPackageName: info) 
     deviceManager = GCKDeviceManager(device: selectedDevice, clientPackageName: "CFBundleIdentifier") 


     //   NSLog("de waarde van info is \(info)") 
     NSLog("de waarde van selectedDevice is \(selectedDevice)") 

     deviceManager.delegate = self 
     deviceManager.connect() 
    } 
} 

    // ==================== deviceDisconnected() ==================== 
func deviceDisconnected() { 
    NSLog("Device disconneted: \(selectedDevice.friendlyName)") 
    deviceManager = nil 
    selectedDevice = nil 
    mediaControlChannel = nil 
    textChannel = nil 
} 

    // ==================== updateButtonStates() ==================== 
func updateButtonStates() { 
    if (deviceScanner.devices.count == 0) { 
     // Hide the cast button 
     chromecastButton.setImage(btnImage, forState: .Normal) 
     chromecastButton.hidden = true 
    } 
    if (deviceScanner.devices.count > 0) { 

     chromecastButton.setImage(btnImage, forState: .Normal) 
     chromecastButton.hidden = false 

     // Show cast button 
     if (deviceManager != nil) { 
      chromecastButton.setImage(btnImageSelected, forState: .Normal) 
      chromecastButton.hidden = false 
     } 
    } 
} 

    // ==================== sendText ==================== 
@IBAction func sendText(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.objectForKey("CFBundleVersion") 

    metaData.setString("Bug Bunny!", forKey: kGCKMetadataKeyTitle) 
    metaData.setString("dit is allemaal maar was subtitles", 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/BigBuckBunny.mp4", streamType: .None, contentType: "video/mp4", metadata: metaData as GCKMediaMetadata, streamDuration: 0, customData: nil) 
    mediaInformation = GCKMediaInformation(contentID: "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4", streamType: GCKMediaStreamType.None, contentType: "video/mp4", metadata: metaData, streamDuration: 0, customData: nil) 


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

    self.mediaControlChannel?.loadMedia(mediaInformation, autoplay: true, playPosition: 0) 
    //  textChannel.sendTextMessage(textFieldUrl.text) 
} 

    // MARK: GCKDeviceScannerListener 
    // ==================== deviceDidComeOnline() ==================== 
func deviceDidComeOnline(device: GCKDevice!) { 
    NSLog("device found! \(device.friendlyName)") 
    updateButtonStates() 
} 

    // ==================== deviceDidGoOffline() ==================== 
func deviceDidGoOffline(device: GCKDevice!) { 
    NSLog("device did go offline \(device.friendlyName)") 
    updateButtonStates() 
} 

    // MARK: UIActionSheetDelegate 
    // ==================== actionSheet() ==================== 
func actionSheet(actionSheet: UIActionSheet, clickedButtonAtIndex buttonIndex: Int) { 
    if selectedDevice == nil { 
     if buttonIndex < deviceScanner.devices.count { 
      selectedDevice = deviceScanner.devices[buttonIndex] as GCKDevice 
      NSLog("Selecting device: \(selectedDevice.friendlyName)") 
      connectToDevice() 
     } 
    } 
    else { 
     if buttonIndex == 1 { 
      NSLog("Disconnecting device: \(selectedDevice.friendlyName)") 
      deviceManager.leaveApplication() 
      deviceManager.disconnect() 
      deviceDisconnected() 
      updateButtonStates() 
     } 
     else if buttonIndex == 0 { 
      // Join the existing session 
     } 
    } 
} 

    // MARK: GCKDeviceManagerDelegate 
    // ==================== deviceManagerDidConnect() ==================== 
func deviceManagerDidConnect(deviceManager: GCKDeviceManager!) { 
    NSLog("Connected!") 
    updateButtonStates() 
    self.deviceManager.launchApplication(kReceiverAppID) 
} 

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


    // textChannel = HTCGTextChannel(namespace: "urn:x-cast:com.silver.essence.Silver") 
    // self.deviceManager.addChannel(textChannel) 


    mediaControlChannel = GCKMediaControlChannel() 
    mediaControlChannel.delegate = self 
    self.deviceManager.addChannel(mediaControlChannel) 
    mediaControlChannel.requestStatus() 
} 

    // ==================== didFailToConnectToApplicationWithError() ==================== 
func deviceManager(deviceManager: GCKDeviceManager!, didFailToConnectToApplicationWithError error: NSError!) { 
    showError(error) 

    deviceDisconnected() 
    updateButtonStates() 
} 

    // ==================== didFailToConnectWithError() ==================== 
func deviceManager(deviceManager: GCKDeviceManager!, didFailToConnectWithError error: NSError!) { 
    showError(error) 

    deviceDisconnected() 
    updateButtonStates() 
} 

    // ==================== didDisconnectWithError() ==================== 
func deviceManager(deviceManager: GCKDeviceManager!, didDisconnectWithError error: NSError!) { 
    NSLog("Received notification that device disconnected") 

    if error != nil { 
     showError(error) 
    } 

    deviceDisconnected() 
    updateButtonStates() 
} 

    // ==================== didReceiveApplicationMetadata() ==================== 
func deviceManager(deviceManager: GCKDeviceManager!, didReceiveApplicationMetadata metadata: GCKApplicationMetadata!) { 
    applicationMetadata = metadata 
} 

    // ==================== showError() ==================== 
func showError(error: NSError) { 
    var alert = UIAlertController(title: "Something went wrong", message: error.description, preferredStyle: UIAlertControllerStyle.Alert) 
    alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil)) 
    presentViewController(alert, animated: true, completion: nil) 
} 

    // ==================== viewDidLoad() ==================== 
override func viewDidLoad() { 
    super.viewDidLoad() 
    self.loadNSUserDefaults() 
    NSNotificationCenter.defaultCenter().addObserver(self, selector: "saveNSUserDefaults", name: "kSaveSwitchesStatesNotification", object: nil); 
    navigationItem.title = "Settings" 

    // ==================== Adding the Chromecast button ==================== 
    //  kReceiverAppID = kGCKMediaDefaultReceiverApplicationID 

    NSLog("de waarde van kReceiverAppID in viewDidLoad() is : \(kReceiverAppID)") 

    btnImage = UIImage(named: "icon-cast-identified") 
    btnImageSelected = UIImage(named: "icon-cast-connected") 

    chromecastButton = UIButton() 
    chromecastButton.setImage(UIImage(named: "icon-cast-identified"), forState: .Normal) 
    chromecastButton.frame = CGRectMake(0, 0, 45, 45) 
    chromecastButton.addTarget(self, action: "chooseDevice", forControlEvents: .TouchUpInside) 
    chromecastButton.hidden = true 

    var rightItem:UIBarButtonItem = UIBarButtonItem() 
    rightItem.customView = chromecastButton 
    self.navigationItem.leftBarButtonItem = rightItem 

    // ==================== Scan for Chromecast devices ==================== 
    deviceScanner = GCKDeviceScanner() 
    filterCriteria = GCKFilterCriteria(forAvailableApplicationWithID: kReceiverAppID) 
    deviceScanner.filterCriteria = filterCriteria 
    deviceScanner.addListener(self) 
    deviceScanner.startScan() 
} 
+0

수신자로 어떤 응용 프로그램을 시작 하시겠습니까? kReceiverAppID를 설정하는 행이 주석 처리 된 것을 볼 수 있습니까? –

답변

2

마침내 문제가 발견되었습니다! 그것은 수신기에있었습니다. 네트워크의 캐스트 장치에 연결할 때 수신자가로드하는 HTML 파일입니다. HTML 파일에 응용 프로그램에 다시 연결할 수있는 적절한 기능이 있는지 확인하십시오. 동일한 문제가 발생하여 몇 주 동안 해결책에 대해 생각하지 않는 사람에게 도움이되기를 바랍니다. 어떤 기능이 필요한지 잘 모르는 경우 Google에서 제공 한 예를 살펴보십시오. https://github.com/googlecast/