我想通過單擊播放器 gui 上的全屏按鈕將播放器切換到橫向模式。我正在使用 expo,所以我使用了 expo 方向,我可以通過呼叫 onfullscreenchange 道具上的函式切換到橫向模式,但是在退出全屏模式后,應用程式被鎖定在橫向模式。我如何解決它?
我的代碼:
視頻播放器.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;
uj5u.com熱心網友回復:
您可以使用從 onFullScreenChange 回傳的布林值來確定播放器是否處于全屏狀態,然后設定正確的方向,我現在無法測驗,但應該是這樣的
onFullScreenChange={isFullscreen => {
if(isFullscreen) { setOrientationToPortrait() }
else { setOrientationToLandscape() }
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/371717.html
標籤:反应原生 内嵌框架 youtube-api 世博会 youtube-iframe-api
上一篇:AzureApplicationInsights與GraphQLAPI的集成-HotChocolateFramework
