Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

background audio for video react-native-video

I am unable to get react-native-video to play mp4 files in the background, It will play mp3s and audio files but it refuses to continue playing the video. I have set the background modes in xcode to on with the audio, airplay and picture in picture selected as well as passing these props in as well

playInBackground={true}
playWhenInactive={true}
ignoreSilentSwitch={'ignore'}

is there additional configuration required when its a video and not just audio?

like image 637
Thomas Yancey Avatar asked Oct 27 '18 18:10

Thomas Yancey


People also ask

How do you make a video background in react-native?

Let's move to the important part: placing the video in the background position. Let's define the styles. // We use StyleSheet from react-native so don't forget to import it //import {StyleSheet} from "react-native"; const { height } = Dimensions. get("window"); const styles = StyleSheet.

How do you play background music in react-native?

To allow background audio playback on iOS, you need to activate the 'Audio, Airplay and Picture in Picture' background mode in Xcode. Without activating it, the audio will only play when the app is in the foreground.


1 Answers

Try the code below:

<Video
    source={{uri: 'http://d23dyxeqlo5psv.cloudfront.net/big_buck_bunny.mp4'}}
    style={{ width: 400, height: 400}}
    muted={false}
    repeat={false}
    resizeMode={"cover"}
    volume={1.0}
    rate={1.0}
    ignoreSilentSwitch={"ignore"}
    playWhenInactive={true}
    playInBackground={true}
  />

Run your project from Xcode after doing the step below not just from React-Native packager.

Set the Capabilities in Xcode:

enter image description here

like image 145
Sateesh Yemireddi Avatar answered Oct 20 '22 17:10

Sateesh Yemireddi