zhenghy

增加视频拖动进度条展示

@@ -30,7 +30,8 @@ export struct DetailPlayShortVideoPage { @@ -30,7 +30,8 @@ export struct DetailPlayShortVideoPage {
30 @Provide videoLandScape?: number = 1; // 视频朝向, 横屏视频:1;竖屏视频:2 30 @Provide videoLandScape?: number = 1; // 视频朝向, 横屏视频:1;竖屏视频:2
31 @Provide newsStatusOfUser: batchLikeAndCollectResult | undefined = undefined // 点赞、收藏状态 31 @Provide newsStatusOfUser: batchLikeAndCollectResult | undefined = undefined // 点赞、收藏状态
32 @Provide followStatus: string = '0' // 关注状态 32 @Provide followStatus: string = '0' // 关注状态
33 - @Provide isOpenDetail: boolean = false 33 + @Provide isOpenDetail: boolean = false // 查看详情按钮点击
  34 + @Provide isDragging: boolean = false // 拖动时间进度条
34 @Consume @Watch('pageShowChange') pageShow: number 35 @Consume @Watch('pageShowChange') pageShow: number
35 @Consume @Watch('pageHideChange') pageHide: number 36 @Consume @Watch('pageHideChange') pageHide: number
36 37
@@ -138,9 +139,13 @@ export struct DetailPlayShortVideoPage { @@ -138,9 +139,13 @@ export struct DetailPlayShortVideoPage {
138 build() { 139 build() {
139 Stack({ alignContent: Alignment.Top }) { 140 Stack({ alignContent: Alignment.Top }) {
140 this.playerViewBuilder() 141 this.playerViewBuilder()
141 - PlayerBottomView()  
142 - PlayerRightView()  
143 - 142 + PlayerBottomView({
  143 + playerController: this.playerController
  144 + })
  145 + PlayerRightView({
  146 + playerController: this.playerController
  147 + })
  148 +
144 } 149 }
145 .height('100%') 150 .height('100%')
146 .width('100%') 151 .width('100%')
  1 +export class PlayerConstants {
  2 + static readonly STATUS_IDLE: number = 0;
  3 + static readonly STATUS_START: number = 1;
  4 + static readonly STATUS_PAUSE: number = 2;
  5 + static readonly STATUS_STOP: number = 3;
  6 +}
  7 +
  8 +
1 @Preview 9 @Preview
2 @Component 10 @Component
3 export struct Test { 11 export struct Test {
4 - build() {  
5 - Stack({ alignContent: Alignment.Top }) { 12 + @State progressVal: number = 10;
  13 + @State status: number = PlayerConstants.STATUS_PAUSE;
6 14
7 - Text('视频').width('100%').height('50%').backgroundColor('#000').fontColor(Color.White) 15 + padding1(num: string) {
  16 + let length = 2;
  17 + for (let len = (num.toString()).length; len < length; len = num.length) {
  18 + num = `${'0'}${num}`;
  19 + }
  20 + return num;
  21 + }
8 22
9 - Row() {  
10 - Text('title')  
11 - Text('contentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontentcontent') 23 + secondToTime(seconds: number) {
  24 + let time = '00:00'
  25 + let hourUnit = 60 * 60;
  26 + let hour = Math.floor(seconds / hourUnit);
  27 + let minute = Math.floor((seconds - hour * hourUnit) / 60);
  28 + let second = seconds - hour * hourUnit - minute * 60;
  29 + if (hour > 0) {
  30 + return `${this.padding1(hour.toString())}${':'}${this.padding1(minute.toString())}${':'}${this.padding1(second.toString())}`;
  31 + }
  32 + if (minute > 0) {
  33 + return `${this.padding1(minute.toString())}${':'}${this.padding1(second.toString())}`;
  34 + } else {
  35 + return `${'00'}${':'}${this.padding1(second.toString())}`;
  36 + }
  37 + }
  38 +
  39 + build() {
  40 + Column() {
  41 +
  42 + Text() {
  43 + Span(this.secondToTime(6))
  44 + Span(' / ')
  45 + Span('00:06')
12 } 46 }
13 - .backgroundColor('#ff0000')  
14 - .align(Alignment.BottomStart)  
15 - .position({ y: '100%' })  
16 - .markAnchor({ y: '100%' }) 47 + .fontSize(24)
  48 + .fontColor(Color.White)
  49 + .fontWeight(600)
  50 + .margin({ bottom: 30 })
  51 +
  52 + // .visibility(Visibility.None)
  53 +
  54 + Slider({
  55 + value: this.progressVal,
  56 + step: 0.01,
  57 + // style: SliderStyle.OutSet
  58 + })
  59 + .blockColor(this.status === PlayerConstants.STATUS_START ? Color.Transparent : $r('app.color.play_block_color'))
  60 + .trackColor(this.status === PlayerConstants.STATUS_START ? $r('app.color.play_track_color') : $r('app.color.pause_track_color'))
  61 + .selectedColor(this.status === PlayerConstants.STATUS_START ? $r('app.color.play_selected_color') : $r('app.color.pause_selected_color'))
  62 + .trackThickness(this.status === PlayerConstants.STATUS_START ? 1 : 4)
  63 + .blockStyle({
  64 + type: this.status === PlayerConstants.STATUS_START ? SliderBlockType.DEFAULT : SliderBlockType.IMAGE,
  65 + image: $r('app.media.ic_player_block')
  66 + })
  67 + .blockSize({ width: 18, height: 12 })
  68 + .width('100%')// .height(19)
  69 + .onChange((value: number, mode: SliderChangeMode) => {
  70 + // this.playerController?.setSeekTime(Math.floor(value), mode);
  71 + })
17 72
18 } 73 }
19 - .width(300)  
20 - .height(600)  
21 - .backgroundColor('#cccccc') 74 + .backgroundColor(Color.Blue)
  75 + .height('100%')
22 } 76 }
23 } 77 }
@@ -26,7 +26,7 @@ const TAG = 'VideoChannelDetail' @@ -26,7 +26,7 @@ const TAG = 'VideoChannelDetail'
26 let timer: number = -1 26 let timer: number = -1
27 27
28 const storage = LocalStorage.getShared(); 28 const storage = LocalStorage.getShared();
29 - 29 +
30 @Entry(storage) 30 @Entry(storage)
31 @Component 31 @Component
32 export struct VideoChannelDetail { 32 export struct VideoChannelDetail {
@@ -2,20 +2,21 @@ import { WDPlayerController } from 'wdPlayer/Index'; @@ -2,20 +2,21 @@ import { WDPlayerController } from 'wdPlayer/Index';
2 import { PlayerTitleView } from './PlayerTitleView' 2 import { PlayerTitleView } from './PlayerTitleView'
3 import { PlayerProgressView } from './PlayerProgressView' 3 import { PlayerProgressView } from './PlayerProgressView'
4 import { PlayerCommentView } from './PlayerCommentView' 4 import { PlayerCommentView } from './PlayerCommentView'
  5 +import { PlayerTimeSeekView } from './PlayerTimeSeekView'
5 6
6 @Component 7 @Component
7 export struct PlayerBottomView { 8 export struct PlayerBottomView {
  9 + private playerController?: WDPlayerController;
8 @Consume showComment?: boolean 10 @Consume showComment?: boolean
9 @Consume isOpenDetail?: boolean 11 @Consume isOpenDetail?: boolean
10 - private playerController?: WDPlayerController; 12 + @Consume isDragging?: boolean
11 13
12 build() { 14 build() {
13 Column() { 15 Column() {
14 PlayerTitleView() 16 PlayerTitleView()
15 PlayerProgressView({ playerController: this.playerController }) 17 PlayerProgressView({ playerController: this.playerController })
16 - .visibility(this.isOpenDetail ? Visibility.None : Visibility.Visible)  
17 if (this.showComment) { 18 if (this.showComment) {
18 - PlayerCommentView().visibility(this.isOpenDetail ? Visibility.None : Visibility.Visible) 19 + PlayerCommentView()
19 } 20 }
20 } 21 }
21 .alignItems(HorizontalAlign.Start) 22 .alignItems(HorizontalAlign.Start)
@@ -3,6 +3,7 @@ import router from '@ohos.router'; @@ -3,6 +3,7 @@ import router from '@ohos.router';
3 @Component 3 @Component
4 export struct PlayerCommentView { 4 export struct PlayerCommentView {
5 @Consume showComment?: boolean 5 @Consume showComment?: boolean
  6 + @Consume isOpenDetail?: boolean
6 @State comment: string = ''; 7 @State comment: string = '';
7 8
8 build() { 9 build() {
@@ -30,5 +31,6 @@ export struct PlayerCommentView { @@ -30,5 +31,6 @@ export struct PlayerCommentView {
30 .backgroundColor(Color.Black) 31 .backgroundColor(Color.Black)
31 .alignItems(VerticalAlign.Center) 32 .alignItems(VerticalAlign.Center)
32 .padding({ left: 16, right: 16, top: 11, bottom: 11 }) 33 .padding({ left: 16, right: 16, top: 11, bottom: 11 })
  34 + .visibility(this.isOpenDetail ? Visibility.None : Visibility.Visible)
33 } 35 }
34 } 36 }
  1 +import { ContentDetailDTO } from 'wdBean/Index';
  2 +import { DateTimeUtils } from 'wdKit/Index';
1 import { PlayerConstants, WDPlayerController } from 'wdPlayer/Index'; 3 import { PlayerConstants, WDPlayerController } from 'wdPlayer/Index';
2 4
3 @Component 5 @Component
4 export struct PlayerProgressView { 6 export struct PlayerProgressView {
5 private playerController?: WDPlayerController; 7 private playerController?: WDPlayerController;
  8 + @Consume contentDetailData: ContentDetailDTO
6 @Consume progressVal: number; 9 @Consume progressVal: number;
  10 + @Consume isOpenDetail: boolean
  11 + @Consume isDragging: boolean
7 @State status: number = PlayerConstants.STATUS_START; 12 @State status: number = PlayerConstants.STATUS_START;
8 13
9 aboutToAppear() { 14 aboutToAppear() {
10 if (this.playerController) { 15 if (this.playerController) {
11 this.playerController.onStatusChange = (status: number) => { 16 this.playerController.onStatusChange = (status: number) => {
12 this.status = status 17 this.status = status
  18 + console.log('=============', this.status)
13 } 19 }
14 } 20 }
15 } 21 }
16 22
17 build() { 23 build() {
18 - Slider({  
19 - value: this.progressVal,  
20 - step: 0.01,  
21 - // style: SliderStyle.OutSet  
22 - })  
23 - .blockColor(this.status === PlayerConstants.STATUS_START ? Color.Transparent : $r('app.color.play_block_color'))  
24 - .trackColor(this.status === PlayerConstants.STATUS_START ? $r('app.color.play_track_color') : $r('app.color.pause_track_color'))  
25 - .selectedColor(this.status === PlayerConstants.STATUS_START ? $r('app.color.play_selected_color') : $r('app.color.pause_selected_color'))  
26 - .trackThickness(this.status === PlayerConstants.STATUS_START ? 1 : 4)  
27 - .blockStyle({  
28 - type: this.status === PlayerConstants.STATUS_START ? SliderBlockType.DEFAULT : SliderBlockType.IMAGE,  
29 - image: $r('app.media.ic_player_block')  
30 - })  
31 - .blockSize({ width: 18, height: 12 })  
32 - .width('100%')  
33 - .height(19)  
34 - .onChange((value: number, mode: SliderChangeMode) => {  
35 - this.playerController?.setSeekTime(Math.floor(value), mode); 24 + Column() {
  25 + Text() {
  26 + Span(DateTimeUtils.secondToTime(Math.floor(this.progressVal / 100 * this.contentDetailData.videoInfo[0].videoDuration)))
  27 + Span(' / ')
  28 + Span(DateTimeUtils.secondToTime(this.contentDetailData.videoInfo[0].videoDuration || 0))
  29 + }
  30 + .fontSize(24)
  31 + .fontColor(Color.White)
  32 + .fontWeight(600)
  33 + .margin({ bottom: 30 })
  34 + .visibility(this.isDragging ? Visibility.Visible : Visibility.None)
  35 +
  36 + Slider({
  37 + value: this.progressVal,
  38 + step: 0.01,
  39 + // style: SliderStyle.OutSet
36 }) 40 })
  41 + .blockColor(this.status === PlayerConstants.STATUS_PAUSE || this.isDragging ? $r('app.color.play_block_color') : Color.Transparent)
  42 + .trackColor(this.status === PlayerConstants.STATUS_PAUSE || this.isDragging ? $r('app.color.pause_track_color') : $r('app.color.play_track_color'))
  43 + .selectedColor(this.status === PlayerConstants.STATUS_PAUSE || this.isDragging ? $r('app.color.pause_selected_color') : $r('app.color.play_selected_color'))
  44 + .trackThickness(this.status === PlayerConstants.STATUS_PAUSE || this.isDragging ? 4 : 1)
  45 + .blockStyle({
  46 + type: this.status === PlayerConstants.STATUS_PAUSE || this.isDragging ? SliderBlockType.IMAGE : SliderBlockType.DEFAULT,
  47 + image: $r('app.media.ic_player_block')
  48 + })
  49 + .blockSize({ width: 18, height: 12 })
  50 + .width('100%')
  51 + .height(19)
  52 + .onChange((value: number, mode: SliderChangeMode) => {
  53 + this.progressVal = value
  54 + if (mode === SliderChangeMode.Moving) {
  55 + this.isDragging = true
  56 + }
  57 + if (mode === SliderChangeMode.End) {
  58 + this.isDragging = false
  59 + }
  60 + this.playerController?.setSeekTime(value, mode);
  61 + console.log('slider onChange:', value, mode)
  62 +
  63 + })
  64 + }.visibility(this.isOpenDetail ? Visibility.None : Visibility.Visible)
37 } 65 }
38 } 66 }
@@ -33,6 +33,7 @@ export struct PlayerRightView { @@ -33,6 +33,7 @@ export struct PlayerRightView {
33 @Consume newsStatusOfUser: batchLikeAndCollectResult 33 @Consume newsStatusOfUser: batchLikeAndCollectResult
34 @Consume followStatus: string 34 @Consume followStatus: string
35 @Consume isOpenDetail: boolean 35 @Consume isOpenDetail: boolean
  36 + @Consume isDragging: boolean
36 @State operationList: OperationItem[] = [ 37 @State operationList: OperationItem[] = [
37 { 38 {
38 icon: $r('app.media.ic_like_uncheck'), 39 icon: $r('app.media.ic_like_uncheck'),
@@ -309,6 +310,6 @@ export struct PlayerRightView { @@ -309,6 +310,6 @@ export struct PlayerRightView {
309 .position({ x: '100%', y: '100%' }) 310 .position({ x: '100%', y: '100%' })
310 .markAnchor({ x: '100%', y: '100%' }) 311 .markAnchor({ x: '100%', y: '100%' })
311 .padding({ bottom: 72 }) 312 .padding({ bottom: 72 })
312 - .visibility(this.isOpenDetail ? Visibility.None : Visibility.Visible) 313 + .visibility(this.isOpenDetail || this.isDragging ? Visibility.None : Visibility.Visible)
313 } 314 }
314 } 315 }
  1 +@Preview
  2 +@Component
  3 +export struct PlayerTimeSeekView {
  4 + build() {
  5 + Row() {
  6 + Text() {
  7 + Span('00:06')
  8 + Span('/')
  9 + Span('00:06')
  10 + }
  11 + .fontSize(24)
  12 + .fontColor(Color.White)
  13 + .fontWeight(600)
  14 +
  15 + }
  16 + }
  17 +}
@@ -9,6 +9,7 @@ export struct PlayerTitleView { @@ -9,6 +9,7 @@ export struct PlayerTitleView {
9 @Consume contentDetailData: ContentDetailDTO 9 @Consume contentDetailData: ContentDetailDTO
10 @Consume windowWidth: number 10 @Consume windowWidth: number
11 @Consume isOpenDetail: boolean 11 @Consume isOpenDetail: boolean
  12 + @Consume isDragging: boolean
12 @State titleHeight: number = 0 13 @State titleHeight: number = 0
13 dialogController: CustomDialogController = new CustomDialogController({ 14 dialogController: CustomDialogController = new CustomDialogController({
14 builder: DetailDialog({ 15 builder: DetailDialog({
@@ -104,6 +105,6 @@ export struct PlayerTitleView { @@ -104,6 +105,6 @@ export struct PlayerTitleView {
104 .width(this.windowWidth - 100 + 'px') 105 .width(this.windowWidth - 100 + 'px')
105 .padding({ left: 16, right: 22 }) 106 .padding({ left: 16, right: 22 })
106 .alignItems(HorizontalAlign.Start) 107 .alignItems(HorizontalAlign.Start)
107 - .visibility(this.isOpenDetail ? Visibility.None : Visibility.Visible) 108 + .visibility(this.isOpenDetail || this.isDragging ? Visibility.None : Visibility.Visible)
108 } 109 }
109 } 110 }