xugenyuan

ref |> 文章详情页视频播放进度条调整

鸿蒙设备正文稿件详情页的视频播放器,播放按钮、进度条、时长样式显示模糊和淡化看不清,需要按安卓进行优化

Signed-off-by: xugenyuan <xugenyuan@wondertek.com.cn>
@@ -29,7 +29,9 @@ export struct WdWebLocalComponent { @@ -29,7 +29,9 @@ export struct WdWebLocalComponent {
29 @State sliderStartTime: string = ''; 29 @State sliderStartTime: string = '';
30 @State currentTime: number = 0; 30 @State currentTime: number = 0;
31 @State durationTime: number = 0; 31 @State durationTime: number = 0;
  32 + @State progressOpacity: number = 1
32 @State durationStringTime: string = ''; 33 @State durationStringTime: string = '';
  34 + private progressTimerNumber: number = 0
33 @State isPause: boolean = true; 35 @State isPause: boolean = true;
34 controller: VideoController = new VideoController() 36 controller: VideoController = new VideoController()
35 @StorageProp('currentBreakpoint') @Watch("currentChanged")currentBreakpoint: string = 'sm'; 37 @StorageProp('currentBreakpoint') @Watch("currentChanged")currentBreakpoint: string = 'sm';
@@ -172,7 +174,7 @@ export struct WdWebLocalComponent { @@ -172,7 +174,7 @@ export struct WdWebLocalComponent {
172 this.positionLeft = Number(data?.data?.positionLeft) || 0 174 this.positionLeft = Number(data?.data?.positionLeft) || 0
173 this.positionTop = Number(data?.data?.positionTop) || 0 175 this.positionTop = Number(data?.data?.positionTop) || 0
174 this.videoLandscape = data?.data?.videoLandscape || '1' 176 this.videoLandscape = data?.data?.videoLandscape || '1'
175 - this.controller.start() 177 + this.startPlay()
176 } 178 }
177 } 179 }
178 /** 180 /**
@@ -206,6 +208,26 @@ export struct WdWebLocalComponent { @@ -206,6 +208,26 @@ export struct WdWebLocalComponent {
206 } 208 }
207 } 209 }
208 210
  211 + startPlay() {
  212 + this.cancelProgressTimer()
  213 + this.controller.start()
  214 + this.startProgressTimer()
  215 + }
  216 +
  217 + startProgressTimer() {
  218 + this.progressTimerNumber = setTimeout(() => {
  219 + animateTo({duration: 1000}, () => {
  220 + this.progressOpacity = 0
  221 + })
  222 + }, 3000)
  223 + }
  224 + cancelProgressTimer() {
  225 + if (this.progressTimerNumber > 0) {
  226 + clearTimeout(this.progressTimerNumber)
  227 + this.progressTimerNumber = 0
  228 + }
  229 + }
  230 +
209 @Builder 231 @Builder
210 videoComp(){ 232 videoComp(){
211 Video({ 233 Video({
@@ -221,6 +243,7 @@ export struct WdWebLocalComponent { @@ -221,6 +243,7 @@ export struct WdWebLocalComponent {
221 .objectFit(ImageFit.Contain) 243 .objectFit(ImageFit.Contain)
222 .onFinish(()=>{ 244 .onFinish(()=>{
223 this.isEndPlay = true 245 this.isEndPlay = true
  246 + this.currentTime = 0
224 }) 247 })
225 .onStart(() => { 248 .onStart(() => {
226 this.isPause = false 249 this.isPause = false
@@ -248,13 +271,23 @@ export struct WdWebLocalComponent { @@ -248,13 +271,23 @@ export struct WdWebLocalComponent {
248 WindowModel.shared.setPreferredOrientation(window.Orientation.PORTRAIT) 271 WindowModel.shared.setPreferredOrientation(window.Orientation.PORTRAIT)
249 } 272 }
250 }) 273 })
  274 + .onClick(() => {
  275 + animateTo({duration: 1000}, () => {
  276 + if (this.progressOpacity <= 0) {
  277 + this.progressOpacity = 1
  278 + } else {
  279 + this.progressOpacity = 0
  280 + }
  281 + })
  282 + })
251 283
252 if (this.isEndPlay){ 284 if (this.isEndPlay){
253 Column(){ 285 Column(){
254 Image($r('app.media.icon_replay')).width(40).height(40) 286 Image($r('app.media.icon_replay')).width(40).height(40)
255 .onClick(() => { 287 .onClick(() => {
256 this.isEndPlay = false 288 this.isEndPlay = false
257 - this.controller.start() 289 + this.progressOpacity = 1
  290 + this.startPlay()
258 }) 291 })
259 292
260 Text('重播').fontColor(Color.White).fontSize(14) 293 Text('重播').fontColor(Color.White).fontSize(14)
@@ -271,9 +304,10 @@ export struct WdWebLocalComponent { @@ -271,9 +304,10 @@ export struct WdWebLocalComponent {
271 .height(24) 304 .height(24)
272 .onClick(() => { 305 .onClick(() => {
273 if (this.isPause) { 306 if (this.isPause) {
274 - this.controller.start() 307 + this.startPlay()
275 } else { 308 } else {
276 this.controller.pause() 309 this.controller.pause()
  310 + this.cancelProgressTimer()
277 } 311 }
278 }) 312 })
279 Row() { 313 Row() {
@@ -298,6 +332,13 @@ export struct WdWebLocalComponent { @@ -298,6 +332,13 @@ export struct WdWebLocalComponent {
298 .blockSize({ width: 18, height: 12 }) 332 .blockSize({ width: 18, height: 12 })
299 .onChange((value: number, mode: SliderChangeMode) => { 333 .onChange((value: number, mode: SliderChangeMode) => {
300 this.controller.setCurrentTime(value); 334 this.controller.setCurrentTime(value);
  335 + if (mode == SliderChangeMode.End) {
  336 + if (this.isPause) {
  337 + this.startPlay()
  338 + } else {
  339 + this.startProgressTimer()
  340 + }
  341 + }
301 }) 342 })
302 Text(DateTimeUtils.getFormattedDuration(this.durationTime * 1000)) 343 Text(DateTimeUtils.getFormattedDuration(this.durationTime * 1000))
303 .fontSize(12) 344 .fontSize(12)
@@ -313,7 +354,11 @@ export struct WdWebLocalComponent { @@ -313,7 +354,11 @@ export struct WdWebLocalComponent {
313 // this.controller.requestFullscreen(true) 354 // this.controller.requestFullscreen(true)
314 // }) 355 // })
315 } 356 }
316 - .opacity(0.8) 357 + .opacity(this.progressOpacity)
  358 + .linearGradient({
  359 + direction: GradientDirection.Top, // 渐变方向
  360 + colors: [[0x20000000, 0.0], [Color.Transparent, 1.0]] // [0x80000000, 0.5],
  361 + })
317 .width("100%") 362 .width("100%")
318 .justifyContent(FlexAlign.SpaceAround) 363 .justifyContent(FlexAlign.SpaceAround)
319 } 364 }