【发布时间】:2020-12-11 18:48:37
【问题描述】:
长时间的听众第一次来电。
到目前为止,当我导航到使用 react-native-video 的屏幕时,我无法从 Spotify 之类的东西中获取背景音乐以在我的 react-native 应用程序中保持活力。在 Android 上,无需进行任何更改即可使其正常工作。我正在使用 react-native (non-expo),目前正在 testflight 上进行测试。
如果这是重复的,请告诉我,但我只找到很多关于如何让您的应用在后台播放的文章(我的问题是相反的),而且我可能不只知道 IOS 对这种类型使用的术语的控制。需要注意的是,此组件的一个实例确实包含音频,但大多数呈现的视频都没有音频。
我试过了:
- 使用 react-native-video 文档中的说明更新 AppDelgate.m:
AppDelegate.m
#import <AVFoundation/AVFoundation.h> // import
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
...
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient error:nil]; // allow
...
}
- 这似乎没有效果
- 使用
ignoreSilentSwitch="ignore"和obey
-
Obey成功允许背景音频继续播放,但将有音频的视频静音。 - 查看源代码,ignoreSilentSwitch=obey 与我添加到 AppDelegate.m 文件中的内容相同,如果使用 isPaused 属性也会被否定。
- 尝试了许多其他涉及音频的道具,希望能走运。
-
在 xcode 中我的应用目标上添加了背景模式 =“音频、Airplay 和画中画”功能。
-
有点哭,质疑我的人生选择。
我使用 react-native-video-controls 实现了 react-native-video,但据我了解,它是具有附加功能的同一个模块。这是实现:
<VideoContainer>
<VideoPlayer
source={currentVideo}
navigator={null}
ref={videoRef}
resizeMode={'cover'}
controlTimeout={1500}
paused={isPaused}
repeat={true}
muted={true}
tapAnywhereToPause={true}
disableBack={true}
disableTimer={true}
disableVolume={true}
disableFullscreen={true}
showOnStart={true}
hideShutterView={true}
/>
</VideoContainer>
非常感谢任何帮助、建议、反馈或反驳!
【问题讨论】:
标签: react-native react-native-ios react-native-video