Does google chromecast iOS SDK support lock screen controls?
Asked Answered
T

3

5

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 enter image description here 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.

Tetra answered 2/4, 2014 at 22:56 Comment(0)
E
6

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

Eddins answered 2/4, 2014 at 23:14 Comment(5)
Thanks Ali. hope it'll be supported in the future versions.Tetra
Ali if you work in this team (as I see in your profile), could you please ask them to correct this section - developers.google.com/cast/docs/… (Sender Lock Screen "...optional for iOS.") if it's not possible to implement this functionality it should be noted there, otherwise it looks confusing. thanks!Tetra
@AliNaddaf, @dmitry-khryukin Guys, has anything been changed for this point for two years? I see GCKDeviceManager is able to work from background (via ignoreAppStateNotifications flag), but I still can't make lock screen controls work with chromecastStayathome
@AlexPeda sorry, I've not been touching chrmoecast since thenTetra
@all Is it possible to mirroring the view content rather playing audio/Video and share to the external display with this ?Penneypenni
P
4

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).
Paintbrush answered 9/3, 2016 at 13:55 Comment(2)
Can You tell me how do You managed to show the lock screen controls, while playing something on chrome cast, because I am stuck on that particular step of my implementation?Fishwife
Is it possible to mirroring the view content rather playing audio/Video and share to the external display with this ?Penneypenni
C
4

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

Codd answered 10/7, 2017 at 17:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.