Showing
3 changed files
with
70 additions
and
19 deletions
| @@ -40,7 +40,7 @@ export struct DetailPlayShortVideoPage { | @@ -40,7 +40,7 @@ export struct DetailPlayShortVideoPage { | ||
| 40 | @Provide isOpenDetail: boolean = false // 查看详情按钮点击 | 40 | @Provide isOpenDetail: boolean = false // 查看详情按钮点击 |
| 41 | @Provide isDragging: boolean = false // 拖动时间进度条 | 41 | @Provide isDragging: boolean = false // 拖动时间进度条 |
| 42 | @Provide status: number = PlayerConstants.STATUS_START; | 42 | @Provide status: number = PlayerConstants.STATUS_START; |
| 43 | - @Consume showCommentList: boolean | 43 | + @Consume @Watch("showCommentListChanged") showCommentList: boolean |
| 44 | @Consume displayDirection: DisplayDirection | 44 | @Consume displayDirection: DisplayDirection |
| 45 | @Consume @Watch('videoStatusChange') switchVideoStatus: boolean | 45 | @Consume @Watch('videoStatusChange') switchVideoStatus: boolean |
| 46 | @Consume @Watch('pageShowChange') pageShow: number | 46 | @Consume @Watch('pageShowChange') pageShow: number |
| @@ -229,6 +229,15 @@ export struct DetailPlayShortVideoPage { | @@ -229,6 +229,15 @@ export struct DetailPlayShortVideoPage { | ||
| 229 | 229 | ||
| 230 | } | 230 | } |
| 231 | 231 | ||
| 232 | + showCommentListChanged() { | ||
| 233 | + if (this.showCommentList) { | ||
| 234 | + this.playerWidth = px2vp(this.windowWidth) | ||
| 235 | + this.playerHeight = px2vp(this.windowWidth) / (16 / 9.0) | ||
| 236 | + } else { | ||
| 237 | + this.calculatePlayerRect() | ||
| 238 | + } | ||
| 239 | + } | ||
| 240 | + | ||
| 232 | build() { | 241 | build() { |
| 233 | Stack({ alignContent: Alignment.Top }) { | 242 | Stack({ alignContent: Alignment.Top }) { |
| 234 | Column() { | 243 | Column() { |
| @@ -305,7 +314,7 @@ export struct DetailPlayShortVideoPage { | @@ -305,7 +314,7 @@ export struct DetailPlayShortVideoPage { | ||
| 305 | 314 | ||
| 306 | @Builder | 315 | @Builder |
| 307 | playerViewBuilder() { | 316 | playerViewBuilder() { |
| 308 | - Stack() { | 317 | + Stack({alignContent: this.showCommentList && this.index === this.currentIndex ? Alignment.Top : Alignment.Center}) { |
| 309 | WDPlayerRenderView({ | 318 | WDPlayerRenderView({ |
| 310 | playerController: this.playerController, | 319 | playerController: this.playerController, |
| 311 | onLoad: async () => { | 320 | onLoad: async () => { |
| @@ -335,7 +344,6 @@ export struct DetailPlayShortVideoPage { | @@ -335,7 +344,6 @@ export struct DetailPlayShortVideoPage { | ||
| 335 | } | 344 | } |
| 336 | .width('100%') | 345 | .width('100%') |
| 337 | .height('100%') | 346 | .height('100%') |
| 338 | - .align(Alignment.Center) | ||
| 339 | 347 | ||
| 340 | } | 348 | } |
| 341 | 349 |
| @@ -103,6 +103,7 @@ export class WDPlayerController { | @@ -103,6 +103,7 @@ export class WDPlayerController { | ||
| 103 | case AVPlayerStatus.PLAYING: | 103 | case AVPlayerStatus.PLAYING: |
| 104 | this.setBright(); | 104 | this.setBright(); |
| 105 | this.status = PlayerConstants.STATUS_START; | 105 | this.status = PlayerConstants.STATUS_START; |
| 106 | + this.avPlayer!.videoScaleType = media.VideoScaleType.VIDEO_SCALE_TYPE_FIT | ||
| 106 | this.watchStatus(); | 107 | this.watchStatus(); |
| 107 | break; | 108 | break; |
| 108 | case AVPlayerStatus.PAUSED: | 109 | case AVPlayerStatus.PAUSED: |
| 1 | import componentUtils from '@ohos.arkui.componentUtils'; | 1 | import componentUtils from '@ohos.arkui.componentUtils'; |
| 2 | import { WDPlayerController } from '../controller/WDPlayerController' | 2 | import { WDPlayerController } from '../controller/WDPlayerController' |
| 3 | -import { WindowModel } from 'wdKit'; | ||
| 4 | -import { Logger } from '../utils/Logger'; | 3 | +import { Logger, WindowModel } from 'wdKit'; |
| 5 | import { enableAliPlayer } from '../utils/GlobalSetting'; | 4 | import { enableAliPlayer } from '../utils/GlobalSetting'; |
| 5 | +import json from '@ohos.util.json'; | ||
| 6 | +import { JSON } from '@kit.ArkTS'; | ||
| 6 | 7 | ||
| 7 | class Size { | 8 | class Size { |
| 8 | width: Length = "100%"; | 9 | width: Length = "100%"; |
| @@ -82,12 +83,17 @@ export struct WDPlayerRenderView { | @@ -82,12 +83,17 @@ export struct WDPlayerRenderView { | ||
| 82 | libraryname: enableAliPlayer && this.enableAliPlayer ? "premierlibrary" : undefined, | 83 | libraryname: enableAliPlayer && this.enableAliPlayer ? "premierlibrary" : undefined, |
| 83 | controller: this.xComponentController | 84 | controller: this.xComponentController |
| 84 | }) | 85 | }) |
| 86 | + .id(this.insId) | ||
| 85 | .onLoad(async (event) => { | 87 | .onLoad(async (event) => { |
| 86 | Logger.info(TAG, 'onLoad') | 88 | Logger.info(TAG, 'onLoad') |
| 87 | - this.xComponentController.setXComponentSurfaceSize({ | ||
| 88 | - surfaceWidth: 1920, | ||
| 89 | - surfaceHeight: 1080 | ||
| 90 | - }); | 89 | + |
| 90 | + if (this.videoHeight > 0 && this.videoWidth > 0) { | ||
| 91 | + this.xComponentController.setXComponentSurfaceRect({ | ||
| 92 | + surfaceWidth: this.videoWidth, | ||
| 93 | + surfaceHeight: this.videoHeight | ||
| 94 | + }); | ||
| 95 | + } | ||
| 96 | + | ||
| 91 | if (enableAliPlayer && this.enableAliPlayer) { | 97 | if (enableAliPlayer && this.enableAliPlayer) { |
| 92 | this.playerController?.setSurfaceId(this.insId) | 98 | this.playerController?.setSurfaceId(this.insId) |
| 93 | } else { | 99 | } else { |
| @@ -98,8 +104,8 @@ export struct WDPlayerRenderView { | @@ -98,8 +104,8 @@ export struct WDPlayerRenderView { | ||
| 98 | } | 104 | } |
| 99 | }) | 105 | }) |
| 100 | .zIndex(1000) | 106 | .zIndex(1000) |
| 101 | - .width(this.selfSize.width) | ||
| 102 | - .height(this.selfSize.height) | 107 | + // .width(this.selfSize.width) |
| 108 | + // .height(this.selfSize.height) | ||
| 103 | } | 109 | } |
| 104 | .onAreaChange(() => { | 110 | .onAreaChange(() => { |
| 105 | this.updateLayout() | 111 | this.updateLayout() |
| @@ -108,19 +114,55 @@ export struct WDPlayerRenderView { | @@ -108,19 +114,55 @@ export struct WDPlayerRenderView { | ||
| 108 | .justifyContent(FlexAlign.Center) | 114 | .justifyContent(FlexAlign.Center) |
| 109 | .height('100%') | 115 | .height('100%') |
| 110 | .width('100%') | 116 | .width('100%') |
| 111 | - .align(this.videoWidth > this.videoHeight ? Alignment.Top : Alignment.Center) | 117 | + // .align(this.videoWidth > this.videoHeight ? Alignment.Top : Alignment.Center) |
| 118 | + .align(Alignment.Center) | ||
| 112 | } | 119 | } |
| 113 | 120 | ||
| 114 | updateLayout() { | 121 | updateLayout() { |
| 122 | + | ||
| 115 | let info = componentUtils.getRectangleById(this.insId); | 123 | let info = componentUtils.getRectangleById(this.insId); |
| 116 | - if (info.size.width > 0 && info.size.height > 0 && this.videoHeight > 0 && this.videoWidth > 0) { | ||
| 117 | - if (info.size.width / info.size.height > this.videoWidth / this.videoHeight) { | ||
| 118 | - let scale = info.size.height / this.videoHeight; | ||
| 119 | - this.selfSize = new Size((this.videoWidth * scale / info.size.width) * 100 + "%", '100%'); | ||
| 120 | - } else { | ||
| 121 | - let scale = info.size.width / this.videoWidth; | ||
| 122 | - this.selfSize = new Size('100%', (this.videoHeight * scale / info.size.height) * 100 + "%"); | 124 | + Logger.debug(TAG, "播放器区域变化: " + JSON.stringify(info)) |
| 125 | + | ||
| 126 | + Logger.debug(TAG, "xComponent rect: " + JSON.stringify(this.xComponentController.getXComponentSurfaceRect())) | ||
| 127 | + | ||
| 128 | + if (info.size.width > 0 && info.size.height > 0) { | ||
| 129 | + | ||
| 130 | + // 竖屏 | ||
| 131 | + if (this.videoHeight > 0 && this.videoWidth > 0 && this.videoWidth < this.videoHeight) { | ||
| 132 | + let ratio = this.videoWidth / this.videoHeight | ||
| 133 | + const height = info.size.width / ratio | ||
| 134 | + | ||
| 135 | + // 竖屏,缩放高度大于 视频区域高度 | ||
| 136 | + if (height > info.size.height) { | ||
| 137 | + | ||
| 138 | + Logger.debug(TAG, "ratio = " + ratio + " ==> new height = " + height) | ||
| 139 | + | ||
| 140 | + Logger.debug(TAG, "高度固定,求宽度: " + info.size.height * ratio) | ||
| 141 | + | ||
| 142 | + this.xComponentController.setXComponentSurfaceRect({ | ||
| 143 | + surfaceWidth: info.size.height * ratio, | ||
| 144 | + surfaceHeight: info.size.height | ||
| 145 | + }); | ||
| 146 | + return | ||
| 147 | + } | ||
| 123 | } | 148 | } |
| 149 | + | ||
| 150 | + this.xComponentController.setXComponentSurfaceRect({ | ||
| 151 | + surfaceWidth: info.size.width, | ||
| 152 | + surfaceHeight: info.size.height | ||
| 153 | + }); | ||
| 124 | } | 154 | } |
| 155 | + | ||
| 156 | + | ||
| 157 | + | ||
| 158 | + // if (info.size.width > 0 && info.size.height > 0 && this.videoHeight > 0 && this.videoWidth > 0) { | ||
| 159 | + // if (info.size.width / info.size.height > this.videoWidth / this.videoHeight) { | ||
| 160 | + // let scale = info.size.height / this.videoHeight; | ||
| 161 | + // this.selfSize = new Size((this.videoWidth * scale / info.size.width) * 100 + "%", '100%'); | ||
| 162 | + // } else { | ||
| 163 | + // let scale = info.size.width / this.videoWidth; | ||
| 164 | + // this.selfSize = new Size('100%', (this.videoHeight * scale / info.size.height) * 100 + "%"); | ||
| 165 | + // } | ||
| 166 | + // } | ||
| 125 | } | 167 | } |
| 126 | } | 168 | } |
-
Please register or login to post a comment