Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Cast new session not starting swift ios

I need a custom view for displaying available devices and connecting. I used GCKDiscoveryManager. which returns a GCKDevice. Now, when I try to start a new session with the device, it fails every time. Here is my code:

let sessionManager = GCKCastContext.sharedInstance().sessionManager
 var devices = [GCKDevice](){
    didSet{
        discoveryTableView.reloadData()
    }
 }

override func viewDidLoad() {
    super.viewDidLoad()

    GCKCastContext.sharedInstance().discoveryManager.add(self)
    GCKCastContext.sharedInstance().discoveryManager.startDiscovery()

    sessionManager.add(self)

}

 func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    let device = devices[indexPath.row]

    print(sessionManager.startSession(with: device))

}

Only the device discovery is working right now.

extension DevicesViewController: GCKDiscoveryManagerListener, GCKSessionManagerListener{
func didUpdateDeviceList() {
    print("did update here")
}

func didInsert(_ device: GCKDevice, at index: UInt) {
    self.devices.append(device)
}

func sessionManager(_ sessionManager: GCKSessionManager, didStart session: GCKSession) {
    sessionManager.currentCastSession!.add(textChannel)
    print("session started")
}

func sessionManager(_ sessionManager: GCKSessionManager, didStart session: GCKCastSession) {
    print("cast session started")
}

func sessionManager(_ sessionManager: GCKSessionManager, didFailToStart session: GCKSession, withError error: Error) {
    print(error.localizedDescription)
}

func sessionManager(_ sessionManager: GCKSessionManager, didFailToStart session: GCKCastSession, withError error: Error) {
    print(error.localizedDescription)
}


}

I have already implemented required codes in AppDelegate.swift as per the documentation.

like image 970
Asmin Ghale Avatar asked Oct 26 '25 10:10

Asmin Ghale


1 Answers

Chromecast SDK is written on Objective-C So you need to add @objc to your listener methods

@objc func sessionManager(_ sessionManager: GCKSessionManager, didStart session: GCKSession) {
    sessionManager.currentCastSession!.add(textChannel)
    print("session started")
}

@objc func sessionManager(_ sessionManager: GCKSessionManager, didStart session: GCKCastSession) {
    print("cast session started")
}

@objc func sessionManager(_ sessionManager: GCKSessionManager, didFailToStart session: GCKSession, withError error: Error) {
    print(error.localizedDescription)
}

@objc func sessionManager(_ sessionManager: GCKSessionManager, didFailToStart session: GCKCastSession, withError error: Error) {
    print(error.localizedDescription)
}
like image 150
oxigen Avatar answered Oct 28 '25 22:10

oxigen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!