iOS-与mpnowplayinginfocenter的Chromecast集成,以提供锁定屏幕控件



我正在开发一个使用GoogleCast Framework的iOS OBJ-C应用程序。

我试图通过MPNowPlayingInfoCenter

使锁定屏幕控件工作

我已将正确的权限添加到我的应用程序中以支持背景。

我像这样初始化铸造设备:

self.chromeCastDeviceManager = [[GCKDeviceManager alloc] initWithDevice:self.selectedChromeCastDevice clientPackageName:[info objectForKey:@"CFBundleIdentifier"] ignoreAppStateNotifications:YES];

当我在接收器上启动媒体时,我会在获得成功的播放响应时尝试启动MPNowPlayingInfoCenter

NSInteger result = [_castControlChannel play]; 
if (!result) {
    //launch has worked
    [[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];
     }
} 

我开始相信MPNowPlayingInfoCenter仅在通过AVKit/ AVFoundation加载时提供媒体会话的控件?我这样说是正确的吗?

如果这是真的,我可能可以在Chromecast上使用play method创建一个AVKit/ AVFoundation a nsinteger。然后迫使Avplayer被隐藏和沉默。然后,我可以捕获媒体控件并将其重定向到Chromecast?

我假设iOS上的YouTube应用是这样吗?Netflix和Spotify都在铸造Chromecast时都不支持锁屏控件。

我已经开发了一种解决方案,可以在锁定屏幕中介绍播放器控件。我正在使用一些hack工作,例如method_exchangeimplementations和静音声音,播放和模拟播放器。

我在这篇文章中也回答了Google Chromecast IOS SDK支持锁定屏幕控件?

到目前为止运行还可以,但可能仍然需要改进。

看看https://github.com/peantunes/google-cast-ios-lock-screen

最新更新