HarmonyOS 鸿蒙Next中pc部分软件识别屏幕为竖屏
HarmonyOS 鸿蒙Next中pc部分软件识别屏幕为竖屏 鸿蒙上的某软件,全屏后会认为当前是竖屏模式,播放视频会旋转90°,能不能给添加一个强制横屏选项
更多关于HarmonyOS 鸿蒙Next中pc部分软件识别屏幕为竖屏的实战教程也可以访问 https://www.itying.com/category-93-b0.html
3 回复
import { window } from '@kit.ArkUI';
@Entry
@Component
struct VideoPlayerPage {
@State videoSrc: Resource = $rawfile('test1.mp4')
@State previewUri: Resource = $r('app.media.favor');
controller: VideoController = new VideoController();
@State curRate: PlaybackSpeed = PlaybackSpeed.Speed_Forward_1_00_X
@State fullHeight: Length = 600
@State isFullScreen: boolean = false
@State winBottomHeight:number=0
// 设置窗口方向
setR(orientation: number) {
window.getLastWindow(getContext(this)).then((win) => {
win.setPreferredOrientation(orientation).then((data) => {
console.log('setWindowOrientation: ' + orientation + ' Succeeded. Data: ' + JSON.stringify(data));
}).catch((err: string) => {
console.log('setWindowOrientation: Failed. Cause: ' + JSON.stringify(err));
});
if(orientation=== 1){
win.setWindowLayoutFullScreen(false)
this.winBottomHeight = 0
}else {
win.setWindowLayoutFullScreen(true).then(()=>{
let type = window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR; // 以导航条避让为例
let avoidArea = win.getWindowAvoidArea(type);
this.winBottomHeight = px2vp(avoidArea.bottomRect.height)
})
}
}).catch((err: string) => {
console.log('setWindowOrientation: Failed to obtain the top window. Cause: ' + JSON.stringify(err));
});
}
build() {
Column() {
Stack({alignContent: Alignment.Bottom}) {
Video({
src: this.videoSrc,
previewUri: this.previewUri,
controller: this.controller
})
.width('100%')
.height(this.fullHeight)
.loop(false)
.objectFit(ImageFit.Contain)
.autoPlay(false)
.controls(false)
// 自定义控制器
Row() {
Text('start').onClick(() => {
this.controller.start() // 开始播放
}).margin(5).fontColor(Color.White)
Text('pause').onClick(() => {
this.controller.pause() // 暂停播放
}).margin(5).fontColor(Color.White)
Text('0.75').onClick(() => {
this.curRate = PlaybackSpeed.Speed_Forward_0_75_X // 0.75倍速播放
}).margin(5).fontColor(Color.White)
Text('1').onClick(() => {
this.curRate = PlaybackSpeed.Speed_Forward_1_00_X // 原倍速播放
}).margin(5).fontColor(Color.White)
Text('2').onClick(() => {
this.curRate = PlaybackSpeed.Speed_Forward_2_00_X // 2倍速播放
}).margin(5).fontColor(Color.White)
Text(this.isFullScreen ? '退出全屏' : '全屏').onClick(() => {
if (this.isFullScreen) {
this.setR(1)
this.fullHeight = 600
} else {
this.setR(4)
this.fullHeight = '100%'
}
this.isFullScreen = !this.isFullScreen
}).fontColor(Color.White)
}.margin({bottom:this.winBottomHeight})
.zIndex(1)
}
}
.width('100%')
.height('100%')
.justifyContent(FlexAlign.Center)
}
}
更多关于HarmonyOS 鸿蒙Next中pc部分软件识别屏幕为竖屏的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
鸿蒙Next中PC软件识别屏幕为竖屏是由于软件未适配横屏显示逻辑。鸿蒙系统通过屏幕方向传感器获取设备状态,但部分第三方应用可能未正确读取或响应系统横屏信号。可检查应用是否调用鸿蒙的display模块接口,或存在固定的竖屏布局设置。系统级屏幕方向管理在设置-显示-屏幕旋转中配置。
在HarmonyOS Next中,部分PC软件可能因未适配横屏模式而错误识别屏幕方向,导致视频旋转90°。建议通过以下方式尝试解决:
- 检查软件设置:部分应用提供屏幕方向锁定选项,可在应用内查找相关设置。
- 系统显示设置:进入“设置-显示-屏幕方向”,尝试手动切换为横屏模式,观察是否生效。
- 开发者选项:若已开启开发者模式,可尝试调整“最小宽度”等参数强制横屏布局(需谨慎操作)。
- 反馈应用开发者:建议通过应用内反馈渠道提交问题,推动其适配鸿蒙横屏逻辑。
目前HarmonyOS Next暂未提供全局强制横屏开关,需依赖应用自身适配。可关注后续系统更新是否增加相关功能。