Search code examples
react-nativeexoplayerreact-native-video

React native video does not use play audio using exoplayer


I'm working on a react native project and i needed to use subtitles so i started using exoplayer with react native video, the problem is that now i don't have audio on any video, does anyone know how can i solve it?


Solution

  • I tried to use react-native-exoplayer but this module has a lot of problems, now I use the react-native-video and I find it better than exoplayer and you can try using it from this link

    and this is an example from react-native-video:

    // Load the module
    
    import Video from 'react-native-video';
    
    // Within your render function, assuming you have a file called
    // "background.mp4" in your project. You can include multiple videos
    // on a single screen if you like.
    
    <Video source={{uri: "background"}}   // Can be a URL or a local file.
           ref={(ref) => {
             this.player = ref
           }}                                      // Store reference
           onBuffer={this.onBuffer}                // Callback when remote video is buffering
           onError={this.videoError}               // Callback when video cannot be loaded
           style={styles.backgroundVideo}
    
    selectedTextTrack={{                 // Subtitles
      type: "title",
      value: "English Subtitles"
    }}
    
    selectedVideoTrack={{
      type: "resolution",
      value: 480
    }}
    
     />
    
    // Later on in your styles..
    var styles = StyleSheet.create({
      backgroundVideo: {
        position: 'absolute',
        top: 0,
        left: 0,
        bottom: 0,
        right: 0,
      },
    });