【问题标题】:react native Boolean condition for react-native-orientation of react-native-videoreact-native-video 的 react-native-orientation 的反应原生布尔条件
【发布时间】:2019-11-12 04:17:07
【问题描述】:

我对 React 原生主题非常陌生。我被困在视频播放器方向的非常简单的检查条件上。

我的代码步骤是:

  1. 以下代码是我的状态,即boolean
state = {
    viewmode: false,
};

2.下面这行代码是我的视频播放器图标(横向和纵向)。

<TouchableWithoutFeedback onPress={this.changeViewModes}>
  <MIcon name={!this.state.viewmode ? "fullscreen" : "fullscreen-exit"} size={30} color="#FFF"></MIcon>
</TouchableWithoutFeedback>

到目前为止,一切都运行良好。但是根据要求,视频播放器必须旋转到横向模式和纵向模式。
所以我写了一个条件,它不能正常工作,只显示一种模式,纵向或横向但不旋转

changeViewModes = () => {
  if (!this.state.viewmode == false) {
    //fullscreen
    this.player.presentFullscreenPlayer();
    Orientation.lockToLandscape();
  } else {
    //fullscreen_exit
    Orientation.lockToPortrait();
  }
};
  1. 视频组件代码

<Video  paused={this.state.paused}
        source={LightVideo}
        style={{ width: "100%", height }}
        resizeMode="contain"
        onLoad={this.handleLoad}
        onProgress={this.handleProgress}
        onEnd={this.handleEnd}
        ref={ref =>

 { this.player = ref;}}
          />

谁能帮我将我的视频播放器旋转到横向模式到纵向模式,反之亦然。

【问题讨论】:

  • viewmode(true) 表示不是全屏?
  • @Lenoarod 确切的问题是,当页面加载时,视频播放器将处于纵向模式,但是当我单击全屏模式时,它会变成我想要的全屏和横向模式,但是现在,如果我再次单击,那么它仍将仅处于横向模式。它不再旋转到纵向模式。
  • @Lenoarod 请查看编辑。我已经粘贴了视频组件代码和图标更改
  • 手动全屏退出手柄时,还要调用dismissFullscreenPlayer
  • @Lenoarod 它不工作

标签: react-native video


【解决方案1】:

我资产viewmodel true 表示全屏。然后你点击你的 Mico 来改变全屏。

// this is your video component
Video source={{uri: "background"}}   
       ref={(ref) => {
         this.player = ref
       } />
state = {
viewmode: false, // true means full screen
};

<TouchableWithoutFeedback onPress = {this.changeViewModes}>
              <MIcon name = {!this.state.viewmode ? "fullscreen" : "fullscreen-exit"} size = {30} color="#FFF"></MIcon>
              </TouchableWithoutFeedback>

changeViewModes = () => {

if(!this.state.viewmode)
{ 
  //fullscreen
  this.player.presentFullscreenPlayer();
  Orientation.lockToLandscape();

} else {

  //fullscreen_exit
  this.player.dismissFullscreenPlayer()  // you don not call this method
  Orientation.lockToPortrait(); 

}
// you also have to update the state
this.setState({
   viewModel:!viewModel

})

}

【讨论】:

  • 即使它的真假我的代码也不起作用。确切的问题是,当页面加载时,视频播放器将处于纵向模式,但是当我单击全屏模式时,它会变为我想要的全屏和横向模式,但是现在如果我再次单击,那么它仍然是仅在横向模式下。它不再旋转到纵向模式。
  • 首先,你的代码不会改变状态,所以图标不会随着状态而改变。并请提供您的视频组件代码。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-10-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多