三折叠设备,应用从单屏展开到三屏再折叠回单屏,点击视频全屏后,横屏播放,退出视频全屏,应用页面无法回归竖屏显示。
- "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;
- }
合作咨询
我们的专家服务团队将竭诚为您提供专业的合作咨询服务
解决方案
精准高效的一站式服务支持,助力开发者商业成功