Miscellaneous
iOS App Transport Security
By default, iOS only allows loading encrypted (https
) URLs. If you need to load content from an unencrypted (http
) source, you must modify your Info.plist
file and add the following entry:
For more details, check this article (opens in a new tab).
Audio Mixing
In future versions, react-native-video
will include an Audio Manager for configuring how videos mix with other audio-playing apps.
On iOS, if you want to allow background music from other apps to continue playing over your video component, update your AppDelegate.m
file:
AppDelegate.m
#import <AVFoundation/AVFoundation.h> // Import the AVFoundation framework
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
...
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient error:nil]; // Allow background audio
...
}
You can also use the ignoreSilentSwitch
prop.
Android Expansion File Usage
Expansion files allow you to include assets exceeding the 100MB APK size limit without requiring an update every time you push a new version.
- Only supports
.mp4
files, and they must not be compressed. - Example command to prevent compression:
zip -r -n .mp4 *.mp4 player.video.example.com
Example Usage in Code:
// Assuming "background.mp4" is included in your expansion file.
<Video
source={{uri: "background", mainVer: 1, patchVer: 0}} // Looks for "background.mp4" in the specified expansion version.
resizeMode="cover" // Fill the whole screen while maintaining aspect ratio.
style={styles.backgroundVideo}
/>
Load Files with the React Native Asset System
The asset system introduced in RN 0.14
allows loading shared image resources across iOS and Android without modifying native code. As of RN 0.31
, the same applies to .mp4
video assets on Android. From RN 0.33
, iOS support was added. Requires react-native-video@0.9.0
or later.
Example:
<Video
source={require('../assets/video/turntable.mp4')}
/>
Play in Background on iOS
To allow audio playback in the background on iOS, set the audio session to AVAudioSessionCategoryPlayback
. See the Apple documentation (opens in a new tab) for more details.
(Note: There is an open ticket to expose this as a prop (opens in a new tab).)