zhanglun_wd

视频加载中动效

@@ -11,7 +11,9 @@ export struct PlayerProgressView { @@ -11,7 +11,9 @@ export struct PlayerProgressView {
11 @Consume isDragging: boolean 11 @Consume isDragging: boolean
12 @Consume status: number 12 @Consume status: number
13 @State videoDuration: number = this.contentDetailData?.videoInfo?.[0]?.videoDuration || 1 13 @State videoDuration: number = this.contentDetailData?.videoInfo?.[0]?.videoDuration || 1
14 - 14 + @State loadingTop: number = 10
  15 + @State loadingWidth: number | string = 1
  16 + @State showLoading: boolean = false
15 aboutToAppear() { 17 aboutToAppear() {
16 if (this.playerController) { 18 if (this.playerController) {
17 this.playerController.onStatusChange = (status: number) => { 19 this.playerController.onStatusChange = (status: number) => {
@@ -20,10 +22,48 @@ export struct PlayerProgressView { @@ -20,10 +22,48 @@ export struct PlayerProgressView {
20 this.playerController.onSeekDone = (status: number) => { 22 this.playerController.onSeekDone = (status: number) => {
21 this.playerController?.play() 23 this.playerController?.play()
22 } 24 }
  25 +
  26 + this.playerController.onLoaded = (loaded: number) => {
  27 + if(loaded == 1) {
  28 + this.loadingWidth = '95%'
  29 + this.showLoading = true
  30 + } else {
  31 + this.loadingWidth = 1
  32 + this.showLoading = false
  33 + }
23 } 34 }
24 } 35 }
  36 + }
  37 +
  38 + /**
  39 + *
  40 + * loading 动效
  41 + */
  42 + @Builder
  43 + playerLoadingBuilder() {
  44 +
  45 + Flex({
  46 + direction: FlexDirection.Row,
  47 + justifyContent: FlexAlign.Center,
  48 + alignItems: ItemAlign.End
  49 + }) {
  50 + Text('')
  51 + .backgroundColor(Color.Gray)
  52 + .width(this.loadingWidth)
  53 + .height(1)
  54 + .animation({ duration: 500, curve: Curve.Ease, iterations: -1, playMode: PlayMode.Normal })
  55 + }
  56 + .width('100%')
  57 + .zIndex(2000)
  58 + .visibility(this.showLoading ? Visibility.Visible: Visibility.Hidden)
  59 + .margin({ bottom: 10 })
  60 + // .markAnchor({ x: 0, y: '100%' })
  61 + }
25 62
26 build() { 63 build() {
  64 + Stack() {
  65 + this.playerLoadingBuilder()
  66 + if(!this.showLoading) {
27 Column() { 67 Column() {
28 Text() { 68 Text() {
29 Span(DateTimeUtils.secondToTime(Math.floor(this.progressVal / 100 * this.videoDuration))) 69 Span(DateTimeUtils.secondToTime(Math.floor(this.progressVal / 100 * this.videoDuration)))
@@ -71,4 +111,6 @@ export struct PlayerProgressView { @@ -71,4 +111,6 @@ export struct PlayerProgressView {
71 } 111 }
72 .visibility(this.isOpenDetail ? Visibility.None : Visibility.Visible) 112 .visibility(this.isOpenDetail ? Visibility.None : Visibility.Visible)
73 } 113 }
  114 + }
  115 + }
74 } 116 }
@@ -27,6 +27,7 @@ export class WDPlayerController { @@ -27,6 +27,7 @@ export class WDPlayerController {
27 private prepareTime:number = 0; //加载时间 27 private prepareTime:number = 0; //加载时间
28 private currentPlayTime:number = 0; //当前播放时间 28 private currentPlayTime:number = 0; //当前播放时间
29 public onVideoSizeChange?: (width: number, height: number) => void; 29 public onVideoSizeChange?: (width: number, height: number) => void;
  30 + public onLoaded?: (loaded: number) => void;
30 public onTimeUpdate?: (position: number, duration: number) => void; 31 public onTimeUpdate?: (position: number, duration: number) => void;
31 public onVolumeUpdate?: (volume: number) => void; 32 public onVolumeUpdate?: (volume: number) => void;
32 public continue?: () => void; 33 public continue?: () => void;
@@ -86,6 +87,9 @@ export class WDPlayerController { @@ -86,6 +87,9 @@ export class WDPlayerController {
86 if (this.surfaceId) { 87 if (this.surfaceId) {
87 this.avPlayer.surfaceId = this.surfaceId; 88 this.avPlayer.surfaceId = this.surfaceId;
88 } 89 }
  90 + if(this.onLoaded) {
  91 + this.onLoaded(1)
  92 + }
89 93
90 this.avPlayer?.prepare(); 94 this.avPlayer?.prepare();
91 break; 95 break;
@@ -101,6 +105,9 @@ export class WDPlayerController { @@ -101,6 +105,9 @@ export class WDPlayerController {
101 } 105 }
102 break; 106 break;
103 case AVPlayerStatus.PLAYING: 107 case AVPlayerStatus.PLAYING:
  108 + if(this.onLoaded) {
  109 + this.onLoaded(2)
  110 + }
104 this.setBright(); 111 this.setBright();
105 this.status = PlayerConstants.STATUS_START; 112 this.status = PlayerConstants.STATUS_START;
106 this.avPlayer!.videoScaleType = media.VideoScaleType.VIDEO_SCALE_TYPE_FIT 113 this.avPlayer!.videoScaleType = media.VideoScaleType.VIDEO_SCALE_TYPE_FIT