长时间监听的首次呼叫者。
到目前为止,我一导航到使用react-native-video的屏幕,就无法从Spotify之类的设备获取背景音乐,从而无法在我的react-native应用程序中存活下来。在Android上,无需更改即可正常工作。我正在使用react-native(non-expo),目前正在testflight上进行测试。
如果这是重复的内容,请告诉我,但我只发现了许多文章,介绍如何使您的应用在后台播放(问题恰恰相反),而且我可能不仅仅知道IOS在此类型中使用的术语控制。重要的是要注意,该组件 DOES 的一个实例包括音频,但是显示的大多数视频都没有音频。
我尝试过:
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
成功地允许背景音频继续播放,但将确实有音频的视频静音。在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>
非常感谢您的帮助,建议,反馈或反驳!
答案 0 :(得分:1)
发现罪魁祸首。
所以我对某些定时声音使用了react-native-audio,它们覆盖了静音和非静音视频。
当您调用react-native-sound Sound.setCategory()方法时,可选的第二个参数是“与他人混合”。将其设置为true并按照react-native-video的建议,只需要做AppDelegate.m中的AVAudioSession配置。
IOS类别(react-native-sound中建议的“播放”除外): ios sound categories
Similar issue that helped me find mine
有关音频的有用的IOS文档:
答案 1 :(得分:0)
我看到您缺少启用backgroundAudio的道具。引用文档:
playInBackground 确定在应用程序处于后台时媒体是否应继续播放。这样一来,客户就可以继续收听音频。
false(默认)-不要继续播放媒体
true-继续播放媒体 要在iOS上使用此功能,您必须:
在Xcode项目中启用背景音频 将ignoreSilentSwitch属性设置为“ ignore” 平台:Android ExoPlayer,Android MediaPlayer,iOS
答案 2 :(得分:0)
对于 iOS:
在使用 react-native-video
时,您还应该添加: