I've tried to implement lock screen controls for google Chromecast video streaming app with the latest GoogleCast framework for iOS (2.1.0).
I've corrected the example Chromecast app - https://github.com/googlecast/CastVideos-ios Have added UIBackgroundModes row to the Info.plist Added MediaPlayer framework. And added the following code to ChromecastDeviceController.m
#import <MediaPlayer/MPNowPlayingInfoCenter.h>
#import <MediaPlayer/MPMediaItem.h>
.......
- (BOOL)loadMedia:(NSURL *)url
thumbnailURL:(NSURL *)thumbnailURL
title:(NSString *)title
subtitle:(NSString *)subtitle
mimeType:(NSString *)mimeType
startTime:(NSTimeInterval)startTime
autoPlay:(BOOL)autoPlay {
.....
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
Class playingInfoCenter = NSClassFromString(@"MPNowPlayingInfoCenter");
if (playingInfoCenter) {
NSDictionary *songInfo = [NSDictionary dictionaryWithObjectsAndKeys:
@"Test artist", MPMediaItemPropertyArtist,
@"Test title", MPMediaItemPropertyTitle,
@"Test Album", MPMediaItemPropertyAlbumTitle,
nil];
[[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:songInfo];
}
return YES;
}
But I don't see any controls on the lock screen during broadcasting.
From these sources I see that it wasn't possible to show any controls on the lock screen for the previous version of Chromecast iOS SDK (2.0), because it Closes sockets going to background mode.
ChromeCast background video playback support iOS
Google Chromecast SDK TearDown in background
https://code.google.com/p/google-cast-sdk/issues/detail?id=138
Is it still the same for Cast SDK 2.1.0? Or I'm doing something wrong and actually it's possible to show controls on the lock screen during chromecasting? Thanks.
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):
- (void)remoteControlReceivedWithEvent:(UIEvent *)event
which is called every time a action (play, pause, next...) occur on lock screen controls.UIEventTypeRemoteControl
was received:
UIEventSubtypeRemoteControlPlay
, I check if google cast is connected and I tell the receiver to play self.mediaControlChannel.play
and the same for pause events. If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With