当应用程序进入后台时如何停止 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 (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...