Showing
1 changed file
with
50 additions
and
16 deletions
| @@ -16,7 +16,8 @@ import { CommentDialogView } from '../view/CommentDialogView'; | @@ -16,7 +16,8 @@ import { CommentDialogView } from '../view/CommentDialogView'; | ||
| 16 | import { window } from '@kit.ArkUI'; | 16 | import { window } from '@kit.ArkUI'; |
| 17 | import { PlayerFullScreenView } from '../view/PlayerFullScreenView'; | 17 | import { PlayerFullScreenView } from '../view/PlayerFullScreenView'; |
| 18 | import { OperRowListView, publishCommentModel } from 'wdComponent/Index'; | 18 | import { OperRowListView, publishCommentModel } from 'wdComponent/Index'; |
| 19 | -import {ParamType,TrackConstants } from 'wdTracking/Index'; | 19 | +import { ParamType, TrackConstants } from 'wdTracking/Index'; |
| 20 | + | ||
| 20 | const TAG = 'DetailPlayShortVideoPage'; | 21 | const TAG = 'DetailPlayShortVideoPage'; |
| 21 | 22 | ||
| 22 | /** | 23 | /** |
| @@ -49,6 +50,8 @@ export struct DetailPlayShortVideoPage { | @@ -49,6 +50,8 @@ export struct DetailPlayShortVideoPage { | ||
| 49 | @Consume showComment: boolean // 是否显示底部评论,首页视频频道传false | 50 | @Consume showComment: boolean // 是否显示底部评论,首页视频频道传false |
| 50 | @State imageVisible: boolean = true | 51 | @State imageVisible: boolean = true |
| 51 | @State ratio: number = 16 / 9 | 52 | @State ratio: number = 16 / 9 |
| 53 | + @State playerWidth: number | string = px2vp(this.windowWidth) | ||
| 54 | + @State playerHeight: number | string = px2vp(this.windowHeight) | ||
| 52 | pageParam: ParamType = {} | 55 | pageParam: ParamType = {} |
| 53 | PageName: string = '' | 56 | PageName: string = '' |
| 54 | 57 | ||
| @@ -93,7 +96,8 @@ export struct DetailPlayShortVideoPage { | @@ -93,7 +96,8 @@ export struct DetailPlayShortVideoPage { | ||
| 93 | } else { | 96 | } else { |
| 94 | this.queryNewsInfoOfUser() | 97 | this.queryNewsInfoOfUser() |
| 95 | if (!this.playerController.getPlayer()) { | 98 | if (!this.playerController.getPlayer()) { |
| 96 | - this.playerController.firstPlay(this.contentDetailData?.videoInfo[0]?.videoUrl || '',this.PageName,this.PageName,this.pageParam); | 99 | + this.playerController.firstPlay(this.contentDetailData?.videoInfo[0]?.videoUrl || '', this.PageName, |
| 100 | + this.PageName, this.pageParam); | ||
| 97 | } else { | 101 | } else { |
| 98 | await this.playerController.play() | 102 | await this.playerController.play() |
| 99 | this.imageVisible = false | 103 | this.imageVisible = false |
| @@ -169,34 +173,62 @@ export struct DetailPlayShortVideoPage { | @@ -169,34 +173,62 @@ export struct DetailPlayShortVideoPage { | ||
| 169 | 173 | ||
| 170 | this.contentTrackingDict() | 174 | this.contentTrackingDict() |
| 171 | } | 175 | } |
| 172 | - contentTrackingDict(){ | 176 | + |
| 177 | + contentTrackingDict() { | ||
| 173 | this.pageParam = { | 178 | this.pageParam = { |
| 174 | 'contentType': `${this.contentDetailData.newsType}`, | 179 | 'contentType': `${this.contentDetailData.newsType}`, |
| 175 | 'contentId': `${this.contentDetailData.newsId}`, | 180 | 'contentId': `${this.contentDetailData.newsId}`, |
| 176 | 'contentName': `${this.contentDetailData.newsTitle || ''}`, | 181 | 'contentName': `${this.contentDetailData.newsTitle || ''}`, |
| 177 | } | 182 | } |
| 178 | - if(this.contentDetailData.newsType == 1) { | 183 | + if (this.contentDetailData.newsType == 1) { |
| 179 | this.PageName = TrackConstants.PageName.VideoDetail // 点播 | 184 | this.PageName = TrackConstants.PageName.VideoDetail // 点播 |
| 180 | - } else if(this.contentDetailData.newsType == 2) { | 185 | + } else if (this.contentDetailData.newsType == 2) { |
| 181 | this.PageName = TrackConstants.PageName.Live_Detail // 直播 | 186 | this.PageName = TrackConstants.PageName.Live_Detail // 直播 |
| 182 | - } else if(this.contentDetailData.newsType == 5) { | 187 | + } else if (this.contentDetailData.newsType == 5) { |
| 183 | this.PageName = TrackConstants.PageName.Summary_Detail // 专题详情页 | 188 | this.PageName = TrackConstants.PageName.Summary_Detail // 专题详情页 |
| 184 | - } else if(this.contentDetailData.newsType == 8) { | 189 | + } else if (this.contentDetailData.newsType == 8) { |
| 185 | this.PageName = TrackConstants.PageName.Article_Detail // 图文详情页 | 190 | this.PageName = TrackConstants.PageName.Article_Detail // 图文详情页 |
| 186 | - } else if(this.contentDetailData.newsType == 9) { | 191 | + } else if (this.contentDetailData.newsType == 9) { |
| 187 | this.PageName = TrackConstants.PageName.Atlas_Detail // 图集详情页 | 192 | this.PageName = TrackConstants.PageName.Atlas_Detail // 图集详情页 |
| 188 | - } else if(this.contentDetailData.newsType == 14 || this.contentDetailData.newsType == 15) { | 193 | + } else if (this.contentDetailData.newsType == 14 || this.contentDetailData.newsType == 15) { |
| 189 | this.PageName = TrackConstants.PageName.DynamicDetail // 动态图文/动态视频 | 194 | this.PageName = TrackConstants.PageName.DynamicDetail // 动态图文/动态视频 |
| 190 | } | 195 | } |
| 191 | - console.log('视频详情页',JSON.stringify(this.pageParam)) | ||
| 192 | - console.log('视频详情页2',JSON.stringify(this.PageName)) | 196 | + console.log('视频详情页', JSON.stringify(this.pageParam)) |
| 197 | + console.log('视频详情页2', JSON.stringify(this.PageName)) | ||
| 193 | } | 198 | } |
| 199 | + | ||
| 194 | async aboutToDisappear(): Promise<void> { | 200 | async aboutToDisappear(): Promise<void> { |
| 195 | console.log(TAG, 'aboutToDisappear', this.index) | 201 | console.log(TAG, 'aboutToDisappear', this.index) |
| 196 | await this.playerController?.pause() | 202 | await this.playerController?.pause() |
| 197 | await this.playerController?.release(); | 203 | await this.playerController?.release(); |
| 198 | } | 204 | } |
| 199 | 205 | ||
| 206 | + /** | ||
| 207 | + * 屏幕变化动态计算播放器宽高 | ||
| 208 | + */ | ||
| 209 | + calculatePlayerRect() { | ||
| 210 | + let width = this.windowWidth | ||
| 211 | + let height = this.windowHeight | ||
| 212 | + if (this.displayDirection === DisplayDirection.VERTICAL) { | ||
| 213 | + width = this.windowWidth | ||
| 214 | + height = this.windowHeight | ||
| 215 | + } else { | ||
| 216 | + width = this.windowHeight | ||
| 217 | + height = this.windowWidth | ||
| 218 | + } | ||
| 219 | + // 视频宽高比屏幕大,则宽度撑满 | ||
| 220 | + if (this.ratio > width / height) { | ||
| 221 | + this.playerWidth = '100%' | ||
| 222 | + this.playerHeight = px2vp(width / this.ratio) | ||
| 223 | + } else { | ||
| 224 | + // 否则高度撑满 | ||
| 225 | + this.playerHeight = '100%' | ||
| 226 | + this.playerWidth = px2vp(height * this.ratio) | ||
| 227 | + } | ||
| 228 | + console.log('calculatePlayerRect=====', this.windowWidth, this.windowHeight) | ||
| 229 | + | ||
| 230 | + } | ||
| 231 | + | ||
| 200 | build() { | 232 | build() { |
| 201 | Stack({ alignContent: Alignment.Top }) { | 233 | Stack({ alignContent: Alignment.Top }) { |
| 202 | Column() { | 234 | Column() { |
| @@ -248,6 +280,7 @@ export struct DetailPlayShortVideoPage { | @@ -248,6 +280,7 @@ export struct DetailPlayShortVideoPage { | ||
| 248 | } | 280 | } |
| 249 | .height('100%') | 281 | .height('100%') |
| 250 | .width('100%') | 282 | .width('100%') |
| 283 | + .onAreaChange(() => this.calculatePlayerRect()) | ||
| 251 | 284 | ||
| 252 | } | 285 | } |
| 253 | 286 | ||
| @@ -261,9 +294,9 @@ export struct DetailPlayShortVideoPage { | @@ -261,9 +294,9 @@ export struct DetailPlayShortVideoPage { | ||
| 261 | Image(this.contentDetailData?.firstFrameImageUri) | 294 | Image(this.contentDetailData?.firstFrameImageUri) |
| 262 | .width('100%') | 295 | .width('100%') |
| 263 | .height(this.windowWidth / this.ratio + 'px') | 296 | .height(this.windowWidth / this.ratio + 'px') |
| 264 | - .opacity(this.imageVisible ? 1 : 0) | 297 | + .opacity(this.imageVisible ? 0.8 : 0) |
| 265 | .animation({ | 298 | .animation({ |
| 266 | - duration: 500, curve: Curve.EaseInOut | 299 | + duration: 350, curve: Curve.EaseInOut |
| 267 | }) | 300 | }) |
| 268 | } | 301 | } |
| 269 | 302 | ||
| @@ -274,12 +307,13 @@ export struct DetailPlayShortVideoPage { | @@ -274,12 +307,13 @@ export struct DetailPlayShortVideoPage { | ||
| 274 | playerController: this.playerController, | 307 | playerController: this.playerController, |
| 275 | onLoad: async () => { | 308 | onLoad: async () => { |
| 276 | if (this.contentDetailData != null && this.contentDetailData?.videoInfo[0] != null) { | 309 | if (this.contentDetailData != null && this.contentDetailData?.videoInfo[0] != null) { |
| 277 | - this.playerController.firstPlay(this.contentDetailData.videoInfo[0].videoUrl,this.PageName,this.PageName,this.pageParam); | 310 | + this.playerController.firstPlay(this.contentDetailData.videoInfo[0].videoUrl, this.PageName, this.PageName, |
| 311 | + this.pageParam); | ||
| 278 | } | 312 | } |
| 279 | } | 313 | } |
| 280 | }) | 314 | }) |
| 281 | - .width(this.displayDirection === DisplayDirection.VERTICAL ? '100%' : this.windowWidth * 16 / 9 + 'px') | ||
| 282 | - .height(this.displayDirection === DisplayDirection.VERTICAL ? this.windowWidth / this.ratio + 'px' : '100%') | 315 | + .width(this.playerWidth) |
| 316 | + .height(this.playerHeight) | ||
| 283 | 317 | ||
| 284 | this.playerCoverBuilder() | 318 | this.playerCoverBuilder() |
| 285 | 319 |
-
Please register or login to post a comment