react-native-video this.player.presentFullscreenPlayer()自动横向

时间:2018-01-15 11:44:29

标签: reactjs react-native

通过使用react-native-video,在iOS中如何调用this.player.presentFullscreenPlayer()并直接旋转到横向。在调用react-native-orientation时,我尝试将Orientation.lockToLandscape();this.player.presentFullscreenPlayer()一起使用,似乎无效。 setFullscreen中有一个函数调用RTCVideo.m,是否有人知道如何修改,以便在触发this.player.presentFullscreenPlayer()时从横向开始,谢谢。

1 个答案:

答案 0 :(得分:0)

我尝试了与react-native-orientation类似的东西,它对我有用。你可以做这种事。

import React from "react";
import PropTypes from "prop-types";
import Orientation from "react-native-orientation";
import VideoPlayer from "react-native-video-controls";


const propTypes = {
  navigation: PropTypes.object.isRequired,
  pageUrl: PropTypes.string.isRequired
};


class VideoDetail extends React.Component {

  componentDidMount () {
    Orientation.unlockAllOrientations();
  }

  componentWillUnmount () {
    Orientation.lockToPortrait();
  }


  render () {
    return (
      <VideoPlayer
        disableFullscreen
        disableVolume
        repeat
        goBack={this.goBack}
        ignoreSilentSwitch={"ignore"}
        source={{
          uri: this.props.pageUrl,
          type: "mp4"
        }}
      />
    );
  }
}

VideoDetail.propTypes = propTypes;

export default VideoDetail;

这将很好地适应旋转。但是包装中存在小故障,它采用默认方向,因为所有方向都已启用,因此您可能希望更改其他整个应用程序将启用横向功能。

static UIInterfaceOrientationMask _orientation = UIInterfaceOrientationMaskAllButUpsideDown;
+ (void)setOrientation: (UIInterfaceOrientationMask)orientation {
  _orientation = orientation;
}
+ (UIInterfaceOrientationMask)getOrientation {
  return _orientation;
}

source