锁定视频为横屏全屏方向(react-native-video)

4
我希望能开发一些应用程序,这些应用程序将导航到video.js文件,并自动触发视频以全屏横向方向播放。我正在使用react-native-video库链接:https://github.com/react-native-community/react-native-video

render() {

    return (
      <View style={styles.container}>
        <View style={styles.fullScreen}>
          <Video
            ref={(ref) => {
              this.player = ref
            }}  
            source={require('../vid/intro-video.mp4')}
            style={styles.nativeVideoControls}
            rate={this.state.rate}
            paused={this.state.paused}
            volume={this.state.volume}
            muted={this.state.muted}
            resizeMode={this.state.resizeMode}
            onLoad={this.onLoad}
            onLoadStart={this.loadStart}
            onBuffer={this.onBuffer}
            onProgress={this.onProgress}
            onEnd={debounce(this.onEnd, 100)}
            repeat={false}
            controls={this.state.controls}
          />
        </View>
      </View>
    );
  }

我试图将以下代码添加到loadStart函数中,但它不起作用...当我旋转视频时,如果不是全屏模式,视频将显示在屏幕底部。

this.player.presentFullscreenPlayer()

图片描述

我试过两种解决方法: 1)在view标签上使用onLayout,但是没有任何效果。 2)使用this.player.presentFullscreenPlayer()仍然无法解决问题。

1个回答

1
我仍然没有找到这个问题的解决方案,但我想分享一下我为临时解决此问题所做的解决方法。
我使用另一个包react-native-orientation,并在componentWillMount中触发lockToLandscape(),然后使用dimension获取设备的宽度和高度。

Orientation.lockToLandscape();
height = Dimensions.get('window').height;
width = Dimensions.get('window').width;

我也在`onLoad`方法中添加了`presentFullScreenPlayer`。

this.player.presentFullscreenPlayer();

我设置视频播放器的宽度和高度,使用从设备尺寸获取的宽度和高度。如果你们有其他方法,请分享 :)谢谢

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接