HarmonyOS鸿蒙Next中全屏播放与小窗播放的切换方式是什么?
HarmonyOS鸿蒙Next中全屏播放与小窗播放的切换方式是什么? 全屏播放与小窗播放的切换方式是什么?
Video组件如何支持全屏播放?在用户切换到全屏或小窗播放时,是否需要开发者手动控制,还是通过属性或事件来自动实现?
-
首先设置窗口方向,通过window的setPreferredOrientation接口来设置屏幕方向,接口文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-window-0000001815246534-V5#ZH-CN_TOPIC_0000001881258981__setpreferredorientation9
-
设置沉浸式窗口,为了使视屏能充斥整个屏幕,防止屏幕上下两边的任务栏等区域影响全屏观看效果,通过window的setWindowLayoutFullScreen接口设置窗口沉浸式,接口文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-window-0000001815246534-V5#ZH-CN_TOPIC_0000001881258981__setwindowlayoutfullscreen9
-
必须通过显隐控制控制其他listItrem是否展示,在本案例里除了展示的XC以外,其他的所有的组件理应不展示,通过参数isLayoutFullScreen以及当前选中的index来判断,并且同样根据isLayoutFullScreen来调整全屏前全屏后的XC的宽高。
核心代码
// 设置窗口方向
function 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 => {
console.log('setWindowOrientation: Failed. Cause: ' + JSON.stringify(err));
});
}).catch(err => {
console.log('setWindowOrientation: Failed to obtain the top window. Cause: ' + JSON.stringify(err));
});
}
// 设置沉浸式窗口
function setFullScreen(isLayoutFullScreen: boolean) {
window.getLastWindow(getContext(this)).then(win => {
win.setWindowLayoutFullScreen(isLayoutFullScreen, err => {
const errCode: number = err.code;
if (errCode) {
console.error('Failed to set the window layout to full-screen mode. Cause:' + JSON.stringify(err));
return;
}
console.info('Succeeded in setting the window layout to full-screen mode.');
});
}).catch(err => {
console.log('setWindowOrientation: Failed to obtain the top window. Cause: ' + JSON.stringify(err));
});
}
// 通过显隐控制控制其他listItrem是否展示
function Column() {
Text(this.item.text)
.visibility(this.isLayoutFullScreen === false ? Visibility.Visible : Visibility.None)
Stack() {
XComponent({ id: 'video_player_id', type: XComponentType.SURFACE, controller: this.mXComponentController })
.onLoad(() => {
this.player = new AVPlayerDemo();
this.player.setSurfaceID(this.mXComponentController.getXComponentSurfaceId());
this.player_changed = !this.player_changed;
this.player.avPlayerLiveDemo(0, this.item.url)
})
Row() {
Button("点击全屏")
.onClick(() => {
this.fangDaIndex = this.index
this.setR(4)
this.isLayoutFullScreen = true;
this.setFullScreen(this.isLayoutFullScreen)
})
.backgroundColor(this.bkColor)
Button("退出全屏")
.onClick(() => {
this.setR(1)
this.isLayoutFullScreen = false;
this.setFullScreen(this.isLayoutFullScreen)
})
.backgroundColor(this.bkColor)
Button("跳转页面")
.onClick(() => {
router.pushUrl({
url : "pages/VideoXCDemo",
params : {
"surfaceId" : this.mXComponentController.getXComponentSurfaceId(),
"videoSour" : this.item
}
})
})
.backgroundColor(this.bkColor)
}
}
.height(this.isLayoutFullScreen ? "100%" : 200)
}
.width('100%')
更多关于HarmonyOS鸿蒙Next中全屏播放与小窗播放的切换方式是什么?的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html


