React本机视频不使用exoplayer播放音频

时间:2020-10-09 16:25:05

标签: react-native exoplayer react-native-video

我正在开发一个React Native项目,我需要使用字幕,所以我开始使用带有React Native视频的exoplayer,问题是现在我的任何视频上都没有音频,有人知道我该如何解决它吗?

1 个答案:

答案 0 :(得分:1)

我尝试使用react-native-exoplayer,但是此模块存在很多问题, 现在我使用react-native-video,并且发现它比exoplayer更好,您可以尝试从此link

使用它

这是来自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,
  },
});