"abilities": [
{
"orientation": "portrait",
}
] this.windowStage?.getMainWindow((err: BusinessError, data: window.Window) => {
if (err.code) {
return
}
data.setPreferredOrientation(window.Orientation.LANDSCAPE)
}) 应用代码中调用了setPreferredOrientation接口改变了屏幕方向,但是退出页面时没有进行方向恢复,导致该场景下,进入页面屏幕方向被改成了横向,退出页面没有进行方向恢复,造成了三屏折回单屏,全屏横向播放视频退出后,屏幕依然是横向。
检查setPreferredOrientation接口调用处的代码逻辑,保证所有用例场景下,如果有修改屏幕方向的代码:setPreferredOrientation(window.Orientation.LANDSCAPE),就需要有屏幕方向恢复的代码:setPreferredOrientation(window.Orientation.PORTRAIT)。
import { window } from '@kit.ArkUI';
@Entry
@Component
struct VideoOrientation {
@State videoSrc: Resource = $rawfile('example.mp4'); // 实际开发替换为实际视频资源
@State curRate: PlaybackSpeed = PlaybackSpeed.Speed_Forward_1_00_X;
private isAutoPlay: boolean = true;
private showControls: boolean = true;
private isShortcutKeyEnabled: boolean = false;
controller: VideoController = new VideoController();
build() {
Column() {
Video({
src: this.videoSrc,
currentProgressRate: this.curRate, // 设置播放速度
controller: this.controller,
})
.width('100%')
.height(600)
.autoPlay(this.isAutoPlay)
.controls(this.showControls)
.enableShortcutKey(this.isShortcutKeyEnabled)
.onFullscreenChange((e?: FullscreenObject) => {
if (e !== undefined) {
if (e.fullscreen === true) {
window.getLastWindow(this.getUIContext().getHostContext(), (err, data) => { // 获取window实例
const errCode: number = err.code;
if (errCode) {
console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
return;
}
let windowClass = data;
windowClass.setPreferredOrientation(window.Orientation.LANDSCAPE);
});
} else {
window.getLastWindow(this.getUIContext().getHostContext(), (err, data) => {
const errCode: number = err.code;
if (errCode) {
console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`);
return;
}
let windowClass = data;
windowClass.setPreferredOrientation(window.Orientation.PORTRAIT);
});
}
}
});
};
}
}
interface FullscreenObject {
fullscreen: boolean;
}