pixuireactcomponents 1.4.0 → 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -2,26 +2,26 @@ import { h } from 'preact';
|
|
|
2
2
|
export interface VideoPlayerProps {
|
|
3
3
|
playUrl: string;
|
|
4
4
|
autoPlay?: boolean;
|
|
5
|
-
isStreaming?: boolean;
|
|
6
5
|
playEvent?: {
|
|
7
6
|
onPlay?: () => void;
|
|
8
7
|
onPause?: () => void;
|
|
9
8
|
onEnded?: () => void;
|
|
10
9
|
onFirstFrame?: () => void;
|
|
11
10
|
};
|
|
12
|
-
elementClass
|
|
13
|
-
playIcon
|
|
14
|
-
pauseIcon
|
|
15
|
-
|
|
11
|
+
elementClass: {
|
|
12
|
+
playIcon: string;
|
|
13
|
+
pauseIcon: string;
|
|
14
|
+
loadingIcon: string;
|
|
15
|
+
reloadIcon: string;
|
|
16
16
|
};
|
|
17
17
|
sliderBG?: {
|
|
18
18
|
outerBG?: string;
|
|
19
19
|
innerBG?: string;
|
|
20
20
|
dotBG?: string;
|
|
21
21
|
};
|
|
22
|
-
|
|
23
|
-
hideSliderDuration?: number;
|
|
24
|
-
};
|
|
22
|
+
hideSliderDuration?: number;
|
|
25
23
|
videoDuration?: number;
|
|
24
|
+
compRef?: any;
|
|
25
|
+
rootClassName?: string;
|
|
26
26
|
}
|
|
27
27
|
export declare const VideoPlayer: (props: VideoPlayerProps) => h.JSX.Element;
|
|
@@ -21,12 +21,6 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
21
21
|
import { h } from 'preact';
|
|
22
22
|
import { useEffect, useRef, useState } from 'preact/hooks';
|
|
23
23
|
import { Slider } from '../slider/Slider';
|
|
24
|
-
var videoWrapperStyle = {
|
|
25
|
-
width: '100%',
|
|
26
|
-
height: '100%',
|
|
27
|
-
position: 'absolute',
|
|
28
|
-
// backgroundColor: '#FFF00066'
|
|
29
|
-
};
|
|
30
24
|
var screenClickerStyle = {
|
|
31
25
|
position: 'absolute',
|
|
32
26
|
width: '100%',
|
|
@@ -34,11 +28,6 @@ var screenClickerStyle = {
|
|
|
34
28
|
alignItems: 'center',
|
|
35
29
|
justifyContent: 'center',
|
|
36
30
|
};
|
|
37
|
-
var loadingContainerStyle = {
|
|
38
|
-
position: 'absolute',
|
|
39
|
-
width: '100%',
|
|
40
|
-
height: '100%',
|
|
41
|
-
};
|
|
42
31
|
// 4个视频播放态
|
|
43
32
|
var VideoStatus;
|
|
44
33
|
(function (VideoStatus) {
|
|
@@ -48,7 +37,7 @@ var VideoStatus;
|
|
|
48
37
|
VideoStatus[VideoStatus["Pause"] = 2] = "Pause";
|
|
49
38
|
VideoStatus[VideoStatus["End"] = 3] = "End";
|
|
50
39
|
})(VideoStatus || (VideoStatus = {}));
|
|
51
|
-
var openLog =
|
|
40
|
+
var openLog = true;
|
|
52
41
|
var videoLog = function () {
|
|
53
42
|
var msg = [];
|
|
54
43
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
@@ -59,27 +48,39 @@ var videoLog = function () {
|
|
|
59
48
|
}
|
|
60
49
|
};
|
|
61
50
|
export var VideoPlayer = function (props) {
|
|
62
|
-
var
|
|
51
|
+
var _a;
|
|
52
|
+
var playUrl = props.playUrl, _b = props.autoPlay, autoPlay = _b === void 0 ? true : _b, playEvent = props.playEvent, elementClass = props.elementClass, _c = props.hideSliderDuration, hideSliderDuration = _c === void 0 ? 3000 : _c, sliderBG = props.sliderBG, videoDuration = props.videoDuration, compRef = props.compRef, rootClassName = props.rootClassName;
|
|
53
|
+
var isStreaming = !playUrl.endsWith('.mp4');
|
|
63
54
|
var refVideo = useRef(null);
|
|
64
|
-
|
|
65
|
-
var
|
|
66
|
-
var
|
|
67
|
-
var
|
|
68
|
-
var _f = useState(false), showSlider = _f[0], setShowSlider = _f[1];
|
|
55
|
+
var _d = useState(VideoStatus.Pause), videoStatus = _d[0], setVideoStatus = _d[1];
|
|
56
|
+
var _e = useState(0), currentTime = _e[0], setCurrentTime = _e[1];
|
|
57
|
+
var _f = useState(0), totalTime = _f[0], setTotalTime = _f[1];
|
|
58
|
+
var _g = useState(false), showSlider = _g[0], setShowSlider = _g[1];
|
|
69
59
|
var sliderTimmer = useRef(null);
|
|
60
|
+
var rootRef = useRef();
|
|
70
61
|
var updatePlayTime = function () {
|
|
71
|
-
// videoLog('updatePlayTime----------------');
|
|
72
|
-
// videoLog('updatePlayTime-----------------pp3', refVideo.current.duration);
|
|
73
62
|
if (videoStatus != VideoStatus.Playing || isStreaming)
|
|
74
63
|
return;
|
|
75
64
|
var playTime = refVideo.current.currentTime;
|
|
76
65
|
var currentSeconds = Math.floor(playTime / 1000 + 0.5);
|
|
77
|
-
var duration =
|
|
66
|
+
var duration = getDuration();
|
|
67
|
+
if (duration == undefined) {
|
|
68
|
+
console.error('该版本的pixui不支持自动获取视频时长,请使用videoDuration设置视频时长');
|
|
69
|
+
}
|
|
78
70
|
var totalSeconds = Math.floor(duration / 1000 + 0.5);
|
|
79
71
|
setCurrentTime(currentSeconds);
|
|
80
72
|
setTotalTime(totalSeconds);
|
|
81
73
|
videoLog('updatePlayTime-----------------', 'currentSeconds:', currentSeconds, 'totalSeconds:', totalSeconds, Math.floor((currentTime / totalTime) * 100 + 0.5));
|
|
82
74
|
};
|
|
75
|
+
var getDuration = function () {
|
|
76
|
+
try {
|
|
77
|
+
return videoDuration || refVideo.current.duration;
|
|
78
|
+
}
|
|
79
|
+
catch (e) {
|
|
80
|
+
console.error('该版本的pixui不支持自动获取视频时长,请手动传入videoDuration');
|
|
81
|
+
return 0;
|
|
82
|
+
}
|
|
83
|
+
};
|
|
83
84
|
useEffect(function () {
|
|
84
85
|
videoLog('Video Status changed: ', videoStatus);
|
|
85
86
|
}, [videoStatus]);
|
|
@@ -93,6 +94,17 @@ export var VideoPlayer = function (props) {
|
|
|
93
94
|
var interval = setInterval(function () {
|
|
94
95
|
updatePlayTimeFunRef.current();
|
|
95
96
|
}, 1000);
|
|
97
|
+
if (isStreaming)
|
|
98
|
+
return;
|
|
99
|
+
var playTime = refVideo.current.currentTime;
|
|
100
|
+
var currentSeconds = Math.floor(playTime / 1000 + 0.5);
|
|
101
|
+
var duration = getDuration();
|
|
102
|
+
if (duration == undefined) {
|
|
103
|
+
console.error('该版本的pixui不支持自动获取视频时长,请手动传入videoDuration');
|
|
104
|
+
}
|
|
105
|
+
var totalSeconds = Math.floor(duration / 1000 + 0.5);
|
|
106
|
+
setCurrentTime(currentSeconds);
|
|
107
|
+
setTotalTime(totalSeconds);
|
|
96
108
|
return function () {
|
|
97
109
|
clearInterval(interval);
|
|
98
110
|
clearInterval(sliderTimmer.current);
|
|
@@ -105,18 +117,28 @@ export var VideoPlayer = function (props) {
|
|
|
105
117
|
refVideo.current.pause();
|
|
106
118
|
};
|
|
107
119
|
var onSliderDrag = function (value) {
|
|
108
|
-
|
|
109
|
-
var totlaTime = (value / 100) * (videoDuration || refVideo.current.duration);
|
|
120
|
+
var totlaTime = (value / 100) * getDuration();
|
|
110
121
|
var playSeconds = Math.floor(totlaTime / 1000 + 0.5);
|
|
122
|
+
console.log('onSliderDrag, set currentTime:', playSeconds);
|
|
111
123
|
setCurrentTime(playSeconds);
|
|
124
|
+
refVideo.current.currentTime = totlaTime / 1000;
|
|
125
|
+
};
|
|
126
|
+
var setShowUI = function (show, direct) {
|
|
127
|
+
if (direct === void 0) { direct = false; }
|
|
128
|
+
if (!direct && hideSliderDuration <= 0) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
setShowSlider(show);
|
|
112
132
|
};
|
|
113
133
|
// 结束拖就3秒隐藏Bar
|
|
114
134
|
var onSliderDragEnd = function () {
|
|
115
135
|
videoLog('onDragEnd-----------------');
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
136
|
+
if (hideSliderDuration > 0) {
|
|
137
|
+
clearTimeout(sliderTimmer.current);
|
|
138
|
+
sliderTimmer.current = setTimeout(function () {
|
|
139
|
+
setShowUI(false);
|
|
140
|
+
}, hideSliderDuration);
|
|
141
|
+
}
|
|
120
142
|
refVideo.current.play();
|
|
121
143
|
};
|
|
122
144
|
var onplaying = function () {
|
|
@@ -139,28 +161,35 @@ export var VideoPlayer = function (props) {
|
|
|
139
161
|
setVideoStatus(VideoStatus.End);
|
|
140
162
|
setCurrentTime(0);
|
|
141
163
|
clearTimeout(sliderTimmer.current);
|
|
142
|
-
|
|
164
|
+
setShowUI(true);
|
|
143
165
|
(playEvent === null || playEvent === void 0 ? void 0 : playEvent.onEnded) && playEvent.onEnded();
|
|
144
166
|
};
|
|
145
167
|
var updateSliderHideTimmer = function () {
|
|
146
168
|
clearTimeout(sliderTimmer.current);
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
169
|
+
if (hideSliderDuration > 0) {
|
|
170
|
+
sliderTimmer.current = setTimeout(function () {
|
|
171
|
+
setShowUI(false);
|
|
172
|
+
}, hideSliderDuration);
|
|
173
|
+
}
|
|
150
174
|
};
|
|
151
175
|
var onScreenClick = function () {
|
|
152
176
|
clearTimeout(sliderTimmer.current);
|
|
153
177
|
if (showSlider) {
|
|
154
|
-
|
|
178
|
+
setShowUI(false, true);
|
|
155
179
|
}
|
|
156
180
|
else {
|
|
157
|
-
|
|
158
|
-
updateSliderHideTimmer();
|
|
181
|
+
setShowUI(true, true);
|
|
159
182
|
}
|
|
183
|
+
updateSliderHideTimmer();
|
|
160
184
|
};
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
185
|
+
if (compRef) {
|
|
186
|
+
compRef.current = {
|
|
187
|
+
clickComp: onScreenClick,
|
|
188
|
+
setShowUI: function (show) {
|
|
189
|
+
setShowUI(show, true);
|
|
190
|
+
},
|
|
191
|
+
};
|
|
192
|
+
}
|
|
164
193
|
var onPause = function () {
|
|
165
194
|
console.warn('onPause');
|
|
166
195
|
setVideoStatus(VideoStatus.Pause);
|
|
@@ -177,7 +206,7 @@ export var VideoPlayer = function (props) {
|
|
|
177
206
|
}
|
|
178
207
|
else if (videoStatus == VideoStatus.Pause) {
|
|
179
208
|
refVideo.current.play();
|
|
180
|
-
|
|
209
|
+
// setShowUI(false);
|
|
181
210
|
clearInterval(sliderTimmer.current);
|
|
182
211
|
}
|
|
183
212
|
else if (videoStatus == VideoStatus.End) {
|
|
@@ -185,12 +214,7 @@ export var VideoPlayer = function (props) {
|
|
|
185
214
|
}
|
|
186
215
|
};
|
|
187
216
|
videoLog('currentTime', currentTime, 'totalTime', totalTime);
|
|
188
|
-
return (h("div", {
|
|
189
|
-
width: '100%',
|
|
190
|
-
height: '100%',
|
|
191
|
-
position: 'absolute',
|
|
192
|
-
backgroundColor: 'rgba(0, 0, 0,1)',
|
|
193
|
-
} },
|
|
217
|
+
return (h("div", { className: rootClassName, ref: rootRef },
|
|
194
218
|
h("video", { ref: refVideo, src: playUrl, "object-fit": "no", autoPlay: autoPlay, style: { width: '100%', height: '100%' }, onPlaying: onplaying, onPlay: onplaying, onError: onerror, onEnded: onended, onPause: onpause, onLoadStart: function () {
|
|
195
219
|
console.warn('onloadstart');
|
|
196
220
|
}, onLoadedData: function () {
|
|
@@ -208,7 +232,7 @@ export var VideoPlayer = function (props) {
|
|
|
208
232
|
? elementClass === null || elementClass === void 0 ? void 0 : elementClass.playIcon
|
|
209
233
|
: elementClass === null || elementClass === void 0 ? void 0 : elementClass.reloadIcon, onClick: function (e) {
|
|
210
234
|
e.stopPropagation();
|
|
211
|
-
|
|
235
|
+
switchPlayState();
|
|
212
236
|
} })) : null),
|
|
213
237
|
showSlider && !isStreaming ? (h("div", { style: {
|
|
214
238
|
width: '100%',
|
|
@@ -225,7 +249,7 @@ export var VideoPlayer = function (props) {
|
|
|
225
249
|
} },
|
|
226
250
|
h("text", null, FormatSecondCountDownTime(currentTime)),
|
|
227
251
|
h("div", { style: { marginRight: '30px', marginLeft: '30px' } },
|
|
228
|
-
h(Slider, __assign({}, progressData, { outerBg: (sliderBG === null || sliderBG === void 0 ? void 0 : sliderBG.outerBG) || '', innerBg: (sliderBG === null || sliderBG === void 0 ? void 0 : sliderBG.innerBG) || '', dotBg: (sliderBG === null || sliderBG === void 0 ? void 0 : sliderBG.dotBG) || '', onDrag: onSliderDrag, onDragEnd: onSliderDragEnd, onDragStart: onSliderDragStart, discrete: totalTime > 0 ? Math.floor((currentTime / totalTime) * 100 + 0.5) : 0 }))),
|
|
252
|
+
h(Slider, __assign({}, progressData, { wrapperWidth: ((_a = rootRef.current) === null || _a === void 0 ? void 0 : _a.clientWidth) - 180, outerBg: (sliderBG === null || sliderBG === void 0 ? void 0 : sliderBG.outerBG) || '', innerBg: (sliderBG === null || sliderBG === void 0 ? void 0 : sliderBG.innerBG) || '', dotBg: (sliderBG === null || sliderBG === void 0 ? void 0 : sliderBG.dotBG) || '', onDrag: onSliderDrag, onDragEnd: onSliderDragEnd, onDragStart: onSliderDragStart, discrete: totalTime > 0 ? Math.floor((currentTime / totalTime) * 100 + 0.5) : 0 }))),
|
|
229
253
|
h("text", null, FormatSecondCountDownTime(totalTime)))) : null));
|
|
230
254
|
};
|
|
231
255
|
var progressData = {
|