long time listener first time caller.
I am so far unsuccessful in getting background music from something like Spotify to stay alive in my react-native app as soon as I navigate to a screen that is using react-native-video. On Android no changes had to be made for that to work. I am using react-native (non-expo) and am currently in testing on testflight.
If this is a duplicate let me know, but I am only finding many articles on how to make your app play in the background (my issue is the opposite), and I may not just know the term IOS uses for this type of control. Important to note that one instance of this component DOES include audio, but the majority of videos presented have no audio.
I've tried:
- updating AppDelgate.m with the instructions from react-native-video docs:
AppDelegate.m
#import <AVFoundation/AVFoundation.h> // import
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
...
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient error:nil]; // allow
...
}
- this had seemingly no effect
- Using
ignoreSilentSwitch="ignore"
andobey
Obey
successfully allows background audio to continue, but mutes the videos that do have audio.- Looking at the source, ignoreSilentSwitch=obey does the same thing as what I added to the AppDelegate.m file and is also negated if you use the isPaused prop.
- Tried many of the other props involving audio hoping to get lucky.
Added Background Modes = "Audio, Airplay, and Picture in Picture" Capability on my app target in xcode.
Cried a little bit and questioned my life choices.
I implemented react-native-video using react-native-video-controls, but as I understand it's the same module with added features. Here is the implemenation:
<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>
Any help, suggestion, feedback or rebuttal is greatly appreciated!