pixuireactcomponents 1.3.70 → 1.3.72
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/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export { CheckBox } from "./src/components/react/app/checkBox/CheckBox";
|
|
|
4
4
|
export { DropDown } from "./src/components/react/app/dropDown/DropDown";
|
|
5
5
|
export { ImageViewer } from "./src/components/react/app/imageViewer/imageViewer";
|
|
6
6
|
export { ToggleGroup } from "./src/components/react/app/togglegroup/ToggleGroup";
|
|
7
|
+
export { VideoPlayer } from "./src/components/react/app/videoPlayer/VideoPlayer";
|
|
7
8
|
export { GradientText } from "./src/components/react/base/gradient/GradientText";
|
|
8
9
|
export { PVideo } from "./src/components/react/base/pixVideo/PixVideo";
|
|
9
10
|
export { OutlineText } from "./src/components/react/base/outlinetext/OutlineText";
|
package/index.js
CHANGED
|
@@ -6,6 +6,7 @@ export { DropDown } from './src/components/react/app/dropDown/DropDown';
|
|
|
6
6
|
export { ImageViewer } from './src/components/react/app/imageViewer/imageViewer';
|
|
7
7
|
export { Slider } from './src/components/react/app/slider/Slider';
|
|
8
8
|
export { ToggleGroup } from './src/components/react/app/togglegroup/ToggleGroup';
|
|
9
|
+
export { VideoPlayer } from './src/components/react/app/videoPlayer/VideoPlayer';
|
|
9
10
|
export { GradientText } from './src/components/react/base/gradient/GradientText';
|
|
10
11
|
export { PVideo } from './src/components/react/base/pixVideo/PixVideo';
|
|
11
12
|
export { OutlineText } from './src/components/react/base/outlinetext/OutlineText';
|
package/package.json
CHANGED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { h } from 'preact';
|
|
2
|
+
export interface VideoPlayerProps {
|
|
3
|
+
playUrl: string;
|
|
4
|
+
autoPlay?: boolean;
|
|
5
|
+
playEvent: {
|
|
6
|
+
onPlay?: () => void;
|
|
7
|
+
onPause?: () => void;
|
|
8
|
+
onEnded?: () => void;
|
|
9
|
+
onFirstFrame?: () => void;
|
|
10
|
+
};
|
|
11
|
+
elementClass: {
|
|
12
|
+
playIcon?: string;
|
|
13
|
+
pauseIcon?: string;
|
|
14
|
+
reloadIcon?: string;
|
|
15
|
+
};
|
|
16
|
+
sliderBG: {
|
|
17
|
+
outerBG?: string;
|
|
18
|
+
innerBG?: string;
|
|
19
|
+
dotBG?: string;
|
|
20
|
+
};
|
|
21
|
+
durations: {
|
|
22
|
+
hideSliderDuration?: number;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export declare const VideoPlayer: (props: VideoPlayerProps) => h.JSX.Element;
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
import { createRef, h } from 'preact';
|
|
13
|
+
import { useEffect, useRef, useState } from 'preact/hooks';
|
|
14
|
+
import { Slider } from '../slider/Slider';
|
|
15
|
+
var videoWrapperStyle = {
|
|
16
|
+
width: '100%',
|
|
17
|
+
height: '100%',
|
|
18
|
+
position: 'absolute',
|
|
19
|
+
// backgroundColor: '#FFF00066'
|
|
20
|
+
};
|
|
21
|
+
var screenClickerStyle = {
|
|
22
|
+
position: 'absolute',
|
|
23
|
+
width: '100%',
|
|
24
|
+
height: '100%',
|
|
25
|
+
alignItems: 'center',
|
|
26
|
+
justifyContent: 'center',
|
|
27
|
+
};
|
|
28
|
+
var loadingContainerStyle = {
|
|
29
|
+
position: 'absolute',
|
|
30
|
+
width: '100%',
|
|
31
|
+
height: '100%',
|
|
32
|
+
};
|
|
33
|
+
// 4个视频播放态
|
|
34
|
+
var VideoStatus;
|
|
35
|
+
(function (VideoStatus) {
|
|
36
|
+
VideoStatus[VideoStatus["Loading"] = 0] = "Loading";
|
|
37
|
+
// LoadError,
|
|
38
|
+
VideoStatus[VideoStatus["Playing"] = 1] = "Playing";
|
|
39
|
+
VideoStatus[VideoStatus["Pause"] = 2] = "Pause";
|
|
40
|
+
VideoStatus[VideoStatus["End"] = 3] = "End";
|
|
41
|
+
})(VideoStatus || (VideoStatus = {}));
|
|
42
|
+
export var VideoPlayer = function (props) {
|
|
43
|
+
var playUrl = props.playUrl, _a = props.autoPlay, autoPlay = _a === void 0 ? true : _a, playEvent = props.playEvent, elementClass = props.elementClass, _b = props.durations, durations = _b === void 0 ? { hideSliderDuration: 3000 } : _b, sliderBG = props.sliderBG;
|
|
44
|
+
var refVideo = createRef();
|
|
45
|
+
var hideSliderDuration = 1000;
|
|
46
|
+
var _c = useState(VideoStatus.Loading), videoStatus = _c[0], setVideoStatus = _c[1];
|
|
47
|
+
var _d = useState(0), currentTime = _d[0], setCurrentTime = _d[1];
|
|
48
|
+
var _e = useState(0), totalTime = _e[0], setTotalTime = _e[1];
|
|
49
|
+
var _f = useState(false), showSlider = _f[0], setShowSlider = _f[1];
|
|
50
|
+
var sliderTimmer = useRef(null);
|
|
51
|
+
var updateInfoTimmer = useRef(null);
|
|
52
|
+
var updatePlayTime = function () {
|
|
53
|
+
console.log('updatePlayTime-----------------pp1', videoStatus);
|
|
54
|
+
console.log('updatePlayTime-----------------pp2', refVideo.current.currentTime);
|
|
55
|
+
console.log('updatePlayTime-----------------pp3', refVideo.current.duration);
|
|
56
|
+
if (videoStatus != VideoStatus.Playing)
|
|
57
|
+
return;
|
|
58
|
+
var playTime = refVideo.current.currentTime;
|
|
59
|
+
var currentSeconds = Math.floor(playTime / 1000 + 0.5);
|
|
60
|
+
var duration = refVideo.current.duration;
|
|
61
|
+
var totalSeconds = Math.floor(duration / 1000 + 0.5);
|
|
62
|
+
setCurrentTime(currentSeconds);
|
|
63
|
+
setTotalTime(totalSeconds);
|
|
64
|
+
console.log('updatePlayTime-----------------', 'currentSeconds:', currentSeconds, 'totalSeconds:', totalSeconds, Math.floor((currentTime / totalTime) * 100 + 0.5));
|
|
65
|
+
};
|
|
66
|
+
//用于更新函数环境
|
|
67
|
+
var updatePlayTimeRef = useRef(updatePlayTime);
|
|
68
|
+
useEffect(function () {
|
|
69
|
+
updatePlayTimeRef.current = updatePlayTime;
|
|
70
|
+
});
|
|
71
|
+
useEffect(function () {
|
|
72
|
+
updatePlayTimeRef.current = updatePlayTime;
|
|
73
|
+
updateInfoTimmer.current = setInterval(function () {
|
|
74
|
+
updatePlayTimeRef.current();
|
|
75
|
+
}, 1000);
|
|
76
|
+
return function () {
|
|
77
|
+
clearInterval(sliderTimmer.current);
|
|
78
|
+
};
|
|
79
|
+
}, []);
|
|
80
|
+
// 开始拖就长显Bar
|
|
81
|
+
var onSliderDragStart = function () {
|
|
82
|
+
console.log('onDragStart-----------------');
|
|
83
|
+
clearTimeout(sliderTimmer.current);
|
|
84
|
+
refVideo.current.pause();
|
|
85
|
+
};
|
|
86
|
+
var onSliderDrag = function (value) {
|
|
87
|
+
console.warn('value: ========================', value);
|
|
88
|
+
var totlaTime = (value / 100) * refVideo.current.duration;
|
|
89
|
+
var playSeconds = Math.floor(totlaTime / 1000 + 0.5);
|
|
90
|
+
setCurrentTime(playSeconds);
|
|
91
|
+
};
|
|
92
|
+
// 结束拖就3秒隐藏Bar
|
|
93
|
+
var onSliderDragEnd = function () {
|
|
94
|
+
console.warn('onDragEnd-----------------');
|
|
95
|
+
clearTimeout(sliderTimmer.current);
|
|
96
|
+
sliderTimmer.current = setTimeout(function () {
|
|
97
|
+
setShowSlider(false);
|
|
98
|
+
}, durations.hideSliderDuration);
|
|
99
|
+
refVideo.current.play();
|
|
100
|
+
};
|
|
101
|
+
var onplaying = function () {
|
|
102
|
+
// 加载第一帧画面
|
|
103
|
+
console.warn('-----------onplaying');
|
|
104
|
+
setVideoStatus(VideoStatus.Playing);
|
|
105
|
+
playEvent.onPlay && playEvent.onPlay();
|
|
106
|
+
clearInterval(updateInfoTimmer.current);
|
|
107
|
+
updateInfoTimmer.current = setInterval(function () {
|
|
108
|
+
updatePlayTimeRef.current();
|
|
109
|
+
}, 1000);
|
|
110
|
+
};
|
|
111
|
+
var onerror = function (error) {
|
|
112
|
+
console.error('----------onerror', JSON.stringify(error));
|
|
113
|
+
// 播放错误,比如给一个无法播放的url
|
|
114
|
+
};
|
|
115
|
+
var onpause = function () {
|
|
116
|
+
console.warn('-----------onpause');
|
|
117
|
+
setVideoStatus(VideoStatus.Pause);
|
|
118
|
+
};
|
|
119
|
+
var onended = function () {
|
|
120
|
+
// 视频播放结束
|
|
121
|
+
console.warn('-----------onended');
|
|
122
|
+
setVideoStatus(VideoStatus.End);
|
|
123
|
+
clearInterval(updateInfoTimmer.current);
|
|
124
|
+
setCurrentTime(0);
|
|
125
|
+
clearTimeout(sliderTimmer.current);
|
|
126
|
+
setShowSlider(true);
|
|
127
|
+
playEvent.onEnded && playEvent.onEnded();
|
|
128
|
+
};
|
|
129
|
+
var updateSliderHideTimmer = function () {
|
|
130
|
+
clearTimeout(sliderTimmer.current);
|
|
131
|
+
sliderTimmer.current = setTimeout(function () {
|
|
132
|
+
setShowSlider(false);
|
|
133
|
+
}, durations.hideSliderDuration);
|
|
134
|
+
};
|
|
135
|
+
var onScreenClick = function () {
|
|
136
|
+
clearTimeout(sliderTimmer.current);
|
|
137
|
+
if (showSlider) {
|
|
138
|
+
setShowSlider(false);
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
setShowSlider(true);
|
|
142
|
+
updateSliderHideTimmer();
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
var onIconClick = function () {
|
|
146
|
+
switchPlayState();
|
|
147
|
+
};
|
|
148
|
+
var onPause = function () {
|
|
149
|
+
console.warn('onPause');
|
|
150
|
+
setVideoStatus(VideoStatus.Pause);
|
|
151
|
+
playEvent.onPause && playEvent.onPause();
|
|
152
|
+
};
|
|
153
|
+
var onFirstFrame = function () {
|
|
154
|
+
console.warn('onFirstFrame');
|
|
155
|
+
playEvent.onFirstFrame && playEvent.onFirstFrame();
|
|
156
|
+
};
|
|
157
|
+
var switchPlayState = function () {
|
|
158
|
+
console.log('switchPlayState ', videoStatus);
|
|
159
|
+
if (videoStatus == VideoStatus.Playing) {
|
|
160
|
+
refVideo.current.pause();
|
|
161
|
+
}
|
|
162
|
+
else if (videoStatus == VideoStatus.Pause) {
|
|
163
|
+
refVideo.current.play();
|
|
164
|
+
setShowSlider(false);
|
|
165
|
+
clearInterval(sliderTimmer.current);
|
|
166
|
+
}
|
|
167
|
+
else if (videoStatus == VideoStatus.End) {
|
|
168
|
+
refVideo.current.load();
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
console.log('currentTime', currentTime, 'totalTime', totalTime);
|
|
172
|
+
return (h("div", { style: {
|
|
173
|
+
width: '100%',
|
|
174
|
+
height: '100%',
|
|
175
|
+
position: 'absolute',
|
|
176
|
+
backgroundColor: 'rgba(0, 0, 0,1)',
|
|
177
|
+
} },
|
|
178
|
+
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 () {
|
|
179
|
+
console.warn('onloadstart');
|
|
180
|
+
}, onLoadedData: function () {
|
|
181
|
+
console.warn('onloadeddata');
|
|
182
|
+
}, onCanPlay: onplaying,
|
|
183
|
+
//@ts-ignore
|
|
184
|
+
onfirstframe: onFirstFrame }),
|
|
185
|
+
h("div", { style: screenClickerStyle, onClick: function (e) {
|
|
186
|
+
console.log('screenClickerStyle click');
|
|
187
|
+
e.stopPropagation();
|
|
188
|
+
onScreenClick();
|
|
189
|
+
} }, showSlider ? (h("div", { className: videoStatus == VideoStatus.Playing
|
|
190
|
+
? elementClass.pauseIcon
|
|
191
|
+
: videoStatus == VideoStatus.Pause
|
|
192
|
+
? elementClass.playIcon
|
|
193
|
+
: elementClass.reloadIcon, onClick: function (e) {
|
|
194
|
+
e.stopPropagation();
|
|
195
|
+
onIconClick();
|
|
196
|
+
} })) : null),
|
|
197
|
+
showSlider ? (h("div", { style: {
|
|
198
|
+
width: '100%',
|
|
199
|
+
height: '15px',
|
|
200
|
+
fontSize: '18px',
|
|
201
|
+
color: '#FFFFFF',
|
|
202
|
+
flexDirection: 'row',
|
|
203
|
+
justifyContent: 'spaceAround',
|
|
204
|
+
alignItems: 'center',
|
|
205
|
+
position: 'absolute',
|
|
206
|
+
bottom: '10px',
|
|
207
|
+
margin: '10px',
|
|
208
|
+
marginBottom: '30px',
|
|
209
|
+
} },
|
|
210
|
+
h("text", null, FormatSecondCountDownTime(currentTime)),
|
|
211
|
+
h("div", { style: { marginRight: '30px', marginLeft: '30px' } },
|
|
212
|
+
h(Slider, __assign({}, progressData, { outerBg: sliderBG.outerBG || '', innerBg: sliderBG.innerBG || '', dotBg: sliderBG.dotBG || '', onDrag: onSliderDrag, onDragEnd: onSliderDragEnd, onDragStart: onSliderDragStart, discrete: totalTime > 0 ? Math.floor((currentTime / totalTime) * 100 + 0.5) : 0 }))),
|
|
213
|
+
h("text", null, FormatSecondCountDownTime(totalTime)))) : null));
|
|
214
|
+
};
|
|
215
|
+
var progressData = {
|
|
216
|
+
percent: 0,
|
|
217
|
+
wrapperHeight: 15,
|
|
218
|
+
wrapperWidth: window.innerWidth - 180,
|
|
219
|
+
height: 3,
|
|
220
|
+
dotWidth: 12,
|
|
221
|
+
dotHeight: 12,
|
|
222
|
+
dotWrapperWidth: 42,
|
|
223
|
+
dotWrapperHeight: 42,
|
|
224
|
+
isDiscrete: true,
|
|
225
|
+
maxDiscrete: 100,
|
|
226
|
+
outerBg: '',
|
|
227
|
+
innerBg: '',
|
|
228
|
+
dotBg: '',
|
|
229
|
+
onDragStart: null,
|
|
230
|
+
onDrag: null,
|
|
231
|
+
onDragEnd: null,
|
|
232
|
+
};
|
|
233
|
+
var FormatSecondCountDownTime = function (seconds) {
|
|
234
|
+
var minutes = Math.floor(seconds / 60);
|
|
235
|
+
var remainingSeconds = seconds % 60;
|
|
236
|
+
var formattedMinutes = minutes < 10 ? "0".concat(minutes) : "".concat(minutes);
|
|
237
|
+
var formattedSeconds = remainingSeconds < 10 ? "0".concat(remainingSeconds) : "".concat(remainingSeconds);
|
|
238
|
+
return "".concat(formattedMinutes, ":").concat(formattedSeconds);
|
|
239
|
+
};
|