【问题标题】:Does google chromecast iOS SDK support lock screen controls?google chromecast iOS SDK 是否支持锁屏控件?
【发布时间】:2014-05-14 12:24:51
【问题描述】:

我尝试使用适用于 iOS 的最新 GoogleCast 框架 (2.1.0) 为 google Chromecast 视频流应用程序实现锁屏控制。

我已更正了示例 Chromecast 应用程序 - https://github.com/googlecast/CastVideos-ios 已将 UIBackgroundModes 行添加到 Info.plist 添加了 MediaPlayer 框架。 并将以下代码添加到 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;
}

但我在直播期间在锁定屏幕上看不到任何控件。

从这些来源中,我发现无法在以前版本的 Chromecast iOS SDK (2.0) 的锁定屏幕上显示任何控件,因为它关闭了进入后台模式的套接字。

ChromeCast background video playback support iOS

Google Chromecast SDK TearDown in background

https://code.google.com/p/google-cast-sdk/issues/detail?id=138

Cast SDK 2.1.0 还是一样吗?或者我做错了什么,实际上可以在 chromecasting 期间在锁定屏幕上显示控件? 谢谢。

【问题讨论】:

    标签: ios iphone chromecast google-cast mpnowplayinginfocenter


    【解决方案1】:

    当前的 iOS Cast SDK 在您锁定屏幕时会断开套接字,因此您目前无法实现该功能。

    【讨论】:

    • 谢谢阿里。希望以后的版本能支持。
    • Ali,如果你在这个团队工作(正如我在你的个人资料中看到的那样),你能否请他们更正这部分 - developers.google.com/cast/docs/…(发件人锁定屏幕“...对于 iOS 是可选的。” ) 如果无法实现此功能,则应在此处注明,否则看起来会令人困惑。谢谢!
    • @AliNaddaf,@dmitry-khryukin 伙计们,两年来这一点有什么改变吗?我看到 GCKDeviceManager 能够在后台工作(通过 ignoreAppStateNotifications 标志),但我仍然无法使锁屏控件与 chromecast 一起工作
    • @AlexPeda 抱歉,从那以后我就没有接触过 chrmoecast
    • @all 是否可以镜像查看内容而不是播放音频/视频并使用此共享到外部显示器?
    【解决方案2】:

    嗯,我希望它可以帮助那些和我有类似问题的人。 :)

    经过大量研究后,我在连接到 google cast 设备时最终使用了ignoreAppStateNotifications 标志(已在接受的答案中引用),就像这样

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

    为了使锁屏控件与 google cast 一起工作(在项目功能上激活背景模式的“音频、AirPlay 和画中画”后):

    • 我在 AppDelegate - (void)remoteControlReceivedWithEvent:(UIEvent *)event 内部使用,每次在锁定屏幕控件上发生操作(播放、暂停、下一个...)时都会调用它。
    • 在这个方法中我有一个开关,所以我可以知道收到了什么样的UIEventTypeRemoteControl
      • 如果是UIEventSubtypeRemoteControlPlay,我会检查是否连接了google cast,并告诉接收器播放self.mediaControlChannel.play,暂停事件也是如此。
      • 对于下一个和以前的事件,这取决于您如何设置与 google cast 的集成,您如何投放媒体,就我而言,每次收到此类操作时,我都会投放不同的歌曲(以前或当前歌曲列表的下一个)。

    【讨论】:

    • 你能告诉我你是如何设法在 chrome cast 上播放某些东西时显示锁定屏幕控件的,因为我被困在我实施的那个特定步骤上吗?
    • 是否可以镜像视图内容而不是播放音频/视频并分享到外部显示器?
    【解决方案3】:

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-01-23
      • 2013-11-03
      • 2017-11-05
      • 1970-01-01
      • 2015-03-16
      • 2016-03-22
      • 2018-06-27
      • 1970-01-01
      相关资源
      最近更新 更多