【问题标题】:iOS - Chromecast integration with MPNowPlayingInfoCenter to provide lock screen controlsiOS - Chromecast 与 MPNowPlayingInfoCenter 集成以提供锁屏控制
【发布时间】:2017-02-21 11:30:37
【问题描述】:

我正在开发一个使用 GoogleCast 框架的 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 NSInteger。然后强制 AVPlayer 隐藏和静音。然后我可以捕捉媒体控件并重定向到 Chromecast?

我假设 iOS 上的 Youtube 应用程序是这样做的? Netflix 和 Spotify 在投射到 chromecast 时都不支持锁屏控制。

【问题讨论】:

  • Spotify也有这个功能,我很想知道它有什么诀窍,这件事有什么新进展吗?

标签: ios objective-c avfoundation google-cast mpnowplayinginfocenter


【解决方案1】:

我开发了一种解决方案,可以在锁定屏幕中显示播放器控件。我正在使用一些技巧来工作,例如 method_exchangeImplementations 和静音来播放和模拟播放器。

这个帖子我也回复了Does google chromecast iOS SDK support lock screen controls?

到目前为止,它工作正常,但可能仍需要改进。

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

【讨论】:

    猜你喜欢
    • 2014-05-14
    • 2017-12-28
    • 2013-12-30
    • 2016-12-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多