PlayerProgressView.ets
4.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import { ContentDetailDTO } from 'wdBean/Index';
import { DateTimeUtils, ToastUtils } from 'wdKit/Index';
import { PlayerConstants, WDPlayerController } from 'wdPlayer/Index';
@Reusable
@Component
export struct PlayerProgressView {
private playerController?: WDPlayerController;
@Consume contentDetailData: ContentDetailDTO
@Consume progressVal: number;
@Consume isOpenDetail: boolean
@Consume isDragging: boolean
@Consume status: number
@State videoDuration: number = this.contentDetailData?.videoInfo?.[0]?.videoDuration || 1
@State loadingTop: number = 10
@State loadingWidth: number | string = 1
@State showLoading: boolean = false
@Consume onlyWifiLoadVideo: boolean
timer: number = 0
aboutToAppear() {
if (this.playerController) {
this.playerController.onSeekDone = (status: number) => {
this.playerController?.play()
}
this.playerController.onLoaded = (loaded: number) => {
if(loaded == 1) {
this.loadingWidth = '95%'
if (this.onlyWifiLoadVideo) {
this.showLoading = true
}
this.timer = setTimeout(() => {
ToastUtils.shortToast('网络出小差了,请检查下网络')
}, 10000)
// console.log("PlayerProgressView11", this.timer)
} else {
// console.log("PlayerProgressView22", this.timer)
clearTimeout(this.timer)
this.loadingWidth = 1
this.showLoading = false
}
}
}
}
/**
*
* loading 动效
*/
@Builder
playerLoadingBuilder() {
Flex({
direction: FlexDirection.Row,
justifyContent: FlexAlign.Center,
alignItems: ItemAlign.End
}) {
Text('')
.backgroundColor(Color.Gray)
.width(this.loadingWidth)
.height(1)
.animation({ duration: 500, curve: Curve.Ease, iterations: -1, playMode: PlayMode.Normal })
}
.width('100%')
.zIndex(2000)
.height(10)
.visibility(this.showLoading ? Visibility.Visible: Visibility.Hidden)
.margin({ bottom: 10 })
// .markAnchor({ x: 0, y: '100%' })
}
build() {
Stack() {
this.playerLoadingBuilder()
if(!this.showLoading) {
Column() {
Text() {
Span(DateTimeUtils.secondToTime(Math.floor(this.progressVal / 100 * this.videoDuration)))
Span(' / ')
Span(DateTimeUtils.secondToTime(this.videoDuration))
}
.fontSize(24)
.fontColor(Color.White)
.fontWeight(600)
.margin({ bottom: 30 })
.visibility(this.isDragging ? Visibility.Visible : Visibility.None)
Slider({
value: this.progressVal,
step: 0.01,
// style: SliderStyle.OutSet
})
.blockColor(this.status === PlayerConstants.STATUS_PAUSE || this.isDragging ? $r('app.color.play_block_color') :
Color.Transparent)
.trackColor(this.status === PlayerConstants.STATUS_PAUSE || this.isDragging ?
$r('app.color.pause_track_color') : $r('app.color.play_track_color'))
.selectedColor(this.status === PlayerConstants.STATUS_PAUSE || this.isDragging ?
$r('app.color.pause_selected_color') : $r('app.color.play_selected_color'))
.trackThickness(this.status === PlayerConstants.STATUS_PAUSE || this.isDragging ? 4 : 1)
.blockStyle({
type: this.status === PlayerConstants.STATUS_PAUSE || this.isDragging ? SliderBlockType.IMAGE :
SliderBlockType.DEFAULT,
image: $r('app.media.ic_player_block')
})
.blockSize({ width: 18, height: 12 })
.width('100%')
.height(19)
.onChange((value: number, mode: SliderChangeMode) => {
this.progressVal = value
if (mode === SliderChangeMode.Moving) {
this.isDragging = true
}
if (mode === SliderChangeMode.End) {
this.isDragging = false
}
this.playerController?.setSeekTime(value, mode);
console.log('slider onChange:', value, mode)
})
}
.visibility(this.isOpenDetail ? Visibility.None : Visibility.Visible)
}
}
}
}