TheWidlarzGroup / react-native-video

A <Video /> component for react-native
https://thewidlarzgroup.github.io/react-native-video/
MIT License
7.19k stars 2.9k forks source link

Audio prop in Video component. #3265

Open xts-bit opened 1 year ago

xts-bit commented 1 year ago

Feature Request

A prop in the Video component for adding audio to a playing video.

Why it is needed

This feature can solve the problems of people who are trying to use react-native-video for displaying videos in a user-generated content app it will completely eliminate the need to use FFmpeg for merging audio to video from the server --Which is a very hard to do in a limited CPU and Ram. It will give bad memory errors While deploying.

Possible implementation

Decide on the API for this feature. You might introduce a new prop, such as audioSource, that allows users to specify an audio file or source URL. 2nd To ensure synchronization between audio and video, you may need to implement additional logic. One approach is to observe the currentTime of both the AVPlayer (for video) and the AVAudioPlayer (for audio) and adjust playback accordingly. Or simply get the video and audio duration as a prop.

Code sample

<Video source={{
     uri: "background.mp4",
     audioTracks="https://somerandomaudiourlfrominter.mp3"
  }}  
  ref={(ref) => {
    this.player = ref
  }}                                    
  onBuffer={this.onBuffer}               
  onError={this.videoError}           
  style={styles.backgroundVideo}

  />
freeboub commented 1 year ago

@xts-bit I updated the description and move the new prop audioTracks in source. I know, that on android this prop must be available at playback start up. I don't think it will make sense to change it during playback. Notice that it would be great to move textTracks in source at the same time !