如何解决当应用程序进入后台时如何停止 AirPlay 媒体暂停
我有一个内置 React Native 的 iOS 应用程序,它使用 react-native-video 包播放视频内容并允许使用 AirPlay。当应用程序进入后台(按主页按钮、锁定屏幕或打开向下滑动菜单)时,视频将暂停,您必须从控制中心或锁定屏幕媒体控件恢复播放。我知道这是 AVPlayer 的预期行为,我正在尝试从 Apple documentation 实施以下解决方案:
删除/恢复 AVPlayerLayer 及其关联的 AVPlayer
所提供的代码片段使用 Swift,我似乎无法在我的 AppDelegate.m 文件中使用 Objective-C 找到实现此目的的完整示例。
/* Remove the AVPlayerLayer from its associated AVPlayer
once the app is in the background. */
- (void)applicationDidEnterBackground:(UIApplication *)application {
MyPlayerLayerView *playerView = <#Get your player view#>;
[[playerView playerLayer] setPlayer:nil]; // remove the player
}
/* Restore the AVPlayer when the app is active again. */
- (void)applicationDidBecomeActive:(UIApplication *)application {
MyPlayerLayerView *playerView = <#Get your player view#>;
[[playerView playerLayer] setPlayer:_player]; // restore the player
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。