wangliang_wd

feat:优化视频详情页转全屏问题

@@ -4,6 +4,7 @@ import { Logger, WindowModel } from 'wdKit'; @@ -4,6 +4,7 @@ import { Logger, WindowModel } from 'wdKit';
4 import { enableAliPlayer } from '../utils/GlobalSetting'; 4 import { enableAliPlayer } from '../utils/GlobalSetting';
5 import json from '@ohos.util.json'; 5 import json from '@ohos.util.json';
6 import { JSON } from '@kit.ArkTS'; 6 import { JSON } from '@kit.ArkTS';
  7 +import { window } from '@kit.ArkUI';
7 8
8 class Size { 9 class Size {
9 width: Length = "100%"; 10 width: Length = "100%";
@@ -159,13 +160,34 @@ export struct WDPlayerRenderView { @@ -159,13 +160,34 @@ export struct WDPlayerRenderView {
159 if (info.size.width > 0 && info.size.height > 0) { 160 if (info.size.width > 0 && info.size.height > 0) {
160 161
161 if (!this.liftVideo) { 162 if (!this.liftVideo) {
  163 +
  164 + //解决全屏展示问题
  165 + const windowClass = WindowModel.shared.getWindowClass(); // 获取应用主窗口
  166 + const rect: window.Rect = windowClass.getWindowProperties().windowRect;
162 let ratio = this.videoWidth / this.videoHeight 167 let ratio = this.videoWidth / this.videoHeight
163 - const height = info.size.width / ratio  
164 - Logger.debug(TAG, "ratio = " + ratio + " ==> new height = " + height) 168 + let width = rect.width
  169 + let height = rect.height
  170 + let playerWidth = 0
  171 + let playerHeight = 0
  172 + width = rect.width
  173 + height = rect.height
  174 + // 视频宽高比屏幕大,则宽度撑满
  175 + //console.log(`cj2024 ratio = ${this.ratio} width / height = ${width / height}`)
  176 + if (ratio > width / height) {
  177 + playerWidth = width
  178 + playerHeight = width / ratio
  179 + } else {
  180 + // 否则高度撑满
  181 + playerHeight = height
  182 + playerWidth = height * ratio
  183 + }
  184 +
  185 + // const height = info.size.width / ratio
  186 + Logger.debug(TAG, "ratio = " + ratio + " ==> new height = " + playerHeight)
165 if (this.videoHeight > 0 && this.videoWidth > 0) { 187 if (this.videoHeight > 0 && this.videoWidth > 0) {
166 this.xComponentController.setXComponentSurfaceRect({ 188 this.xComponentController.setXComponentSurfaceRect({
167 - surfaceWidth: info.size.width,  
168 - surfaceHeight: info.size.width / this.videoRatio, 189 + surfaceWidth: playerWidth,
  190 + surfaceHeight: playerHeight,
169 // offsetY: this.isPad ? this.topSafeHeight : (info.size.height - height) / 2 191 // offsetY: this.isPad ? this.topSafeHeight : (info.size.height - height) / 2
170 }); 192 });
171 return 193 return