Does google chromecast iOS SDK support lock screen controls?

旧巷老猫 提交于 2019-12-05 12:03:46

The current iOS Cast SDK disconnects the socket when you lock your screen, so you cannot currently implement that.

Well, I hope it helps someone that have a similar problem as I had. :)

After a lot of research I ended up using ignoreAppStateNotifications flag (which was quoted on the accepted answer) when connecting to a google cast device, like this

self.deviceManager =
    [[GCKDeviceManager alloc] initWithDevice:_selectedDevice
                           clientPackageName:[NSBundle mainBundle].bundleIdentifier
                            ignoreAppStateNotifications:YES];

For making lock screen controls work with google cast (after activate "Audio, AirPlay and Picture in Picture" of Background Modes on project Capabilities):

  • I'm using inside AppDelegate - (void)remoteControlReceivedWithEvent:(UIEvent *)event which is called every time a action (play, pause, next...) occur on lock screen controls.
  • Inside this method I have a switch so I can know what kind of UIEventTypeRemoteControl was received:
    • if it was UIEventSubtypeRemoteControlPlay, I check if google cast is connected and I tell the receiver to play self.mediaControlChannel.play and the same for pause events.
    • For next and previous events, it'll depends on how your integration with google cast are set, how you're casting your media, on my case, every time I received this kind of action I cast a different song (previous or next of the current list of songs).

I have developed a solution to present the player controls in the lock screen. I am using some hacks to work, like method_exchangeImplementations and a mute sound to play and mock the player.

So far it works ok, but probably still improvements.

Take a look at https://github.com/peantunes/google-cast-ios-lock-screen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!