【发布时间】:2023-03-10 01:15:01
【问题描述】:
我想通过单击播放器 gui 上的全屏按钮将播放器切换到横向模式。我正在使用博览会,所以我使用博览会方向,我可以通过调用 onfullscreenchange 道具上的函数切换到横向模式,但是在退出全屏模式后,应用程序被锁定在横向模式。我该如何解决?
我的代码:
VideoPlayer.js
import React from "react";
import { View, Dimensions } from "react-native";
import YoutubePlayer from "react-native-youtube-iframe";
import * as ScreenOrientation from "expo-screen-orientation";
const VideoPlayer = () => {
function setOrientation() {
if (Dimensions.get("window").height > Dimensions.get("window").width) {
//Device is in portrait mode, rotate to landscape mode.
ScreenOrientation.lockAsync(ScreenOrientation.OrientationLock.LANDSCAPE);
} else {
//Device is in landscape mode, rotate to portrait mode.
ScreenOrientation.lockAsync(ScreenOrientation.OrientationLock.PORTRAIT);
}
}
return (
<View
style={{
width: "100%",
height: 220,
}}
>
<YoutubePlayer
height={300}
play={false}
videoId={"Dv7gLpW91DM"}
onFullScreenChange={setOrientation}
/>
</View>
);
};
export default VideoPlayer;
【问题讨论】:
标签: react-native iframe youtube-api expo youtube-iframe-api