tencent.jquery.pix.component 1.0.53 → 1.0.61
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.
|
@@ -24,6 +24,9 @@ export function Banner(options = {}){
|
|
|
24
24
|
this.options.durationMs = Number(options.durationMs || 0) || 0;
|
|
25
25
|
this.options.dragThreshold = Number(options.dragThreshold || 0.2) || 0.2;
|
|
26
26
|
this.index = Number(options.index || 0) || 0;
|
|
27
|
+
if (typeof options.renderCallback === 'function') {
|
|
28
|
+
this.options.isTitleEnabled = false;
|
|
29
|
+
}
|
|
27
30
|
this.init();
|
|
28
31
|
}
|
|
29
32
|
|
|
@@ -148,6 +151,9 @@ Banner.prototype.startAutoPlay = function() {
|
|
|
148
151
|
}
|
|
149
152
|
|
|
150
153
|
Banner.prototype.pauseAutoPlay = function() {
|
|
154
|
+
if (this.timer == null) {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
151
157
|
clearInterval(this.timer);
|
|
152
158
|
this.timer = null;
|
|
153
159
|
}
|
|
@@ -442,6 +448,7 @@ Banner.prototype.loadBackground = function (pos) {
|
|
|
442
448
|
}
|
|
443
449
|
|
|
444
450
|
Banner.prototype.remove = function () {
|
|
451
|
+
this.pauseAutoPlay();
|
|
445
452
|
$(this.options.container).empty();
|
|
446
453
|
removeResizeFunc({
|
|
447
454
|
obj: this,
|
|
@@ -2,6 +2,11 @@ import { $, windowEnv } from "../config";
|
|
|
2
2
|
import VideoHTML from "./videohtml";
|
|
3
3
|
import './videocss.scss'
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* @typedef {"play" | "pause" | "stop" | "enterFullScreen" | "exitFullScreen"} VideoPlayerState
|
|
7
|
+
* 视频播放器状态
|
|
8
|
+
*/
|
|
9
|
+
|
|
5
10
|
/**
|
|
6
11
|
* 在页面上放置一个视频播放器组件(腾讯视频)
|
|
7
12
|
* @constructor
|
|
@@ -12,9 +17,14 @@ import './videocss.scss'
|
|
|
12
17
|
* @param {0|1} [options.videoType=1] 视频类型选项,0: 标清,1: 高清
|
|
13
18
|
* @param {number} [options.autoHideControlsDelayMs=5000] 自动隐藏控制条延迟时间,单位ms
|
|
14
19
|
* @param {boolean} [options.showProgressBar=true] 是否显示进度条
|
|
20
|
+
* @param {boolean} [options.clickToPause=false] 点击播放区域是否直接暂停,true: 直接暂停,false: 先展示控制条
|
|
21
|
+
* @param {(this: VideoPlayer, type: VideoPlayerState) => any} [options.stateChanged] 状态变化回调
|
|
15
22
|
*/
|
|
16
23
|
export function VideoPlayer(options) {
|
|
17
24
|
this.options = options
|
|
25
|
+
if (typeof this.options.stateChanged !== 'function') {
|
|
26
|
+
this.options.stateChanged = () => {};
|
|
27
|
+
}
|
|
18
28
|
this.init()
|
|
19
29
|
}
|
|
20
30
|
|
|
@@ -38,6 +48,7 @@ VideoPlayer.prototype.init = async function() {
|
|
|
38
48
|
videoType: 1,
|
|
39
49
|
autoHideControlsDelayMs: 5000,
|
|
40
50
|
showProgressBar: true,
|
|
51
|
+
clickToPause: false,
|
|
41
52
|
...this.options
|
|
42
53
|
}
|
|
43
54
|
|
|
@@ -48,7 +59,8 @@ VideoPlayer.prototype.init = async function() {
|
|
|
48
59
|
playing: false,
|
|
49
60
|
controlsVisible: false,
|
|
50
61
|
updatingProgress: false,
|
|
51
|
-
controlsDelayStart: 0
|
|
62
|
+
controlsDelayStart: 0,
|
|
63
|
+
firstPlay: true,
|
|
52
64
|
}
|
|
53
65
|
|
|
54
66
|
// 根据showProgressBar选项控制进度条显示
|
|
@@ -63,8 +75,6 @@ VideoPlayer.prototype.bindEvent = function() {
|
|
|
63
75
|
const container = this.$container;
|
|
64
76
|
container.off()
|
|
65
77
|
.on('click', '.myplayer-video-cover', () => {
|
|
66
|
-
container.find('.myplayer-video-cover,.myplayer-video-preview').remove();
|
|
67
|
-
this.updateTotalTime();
|
|
68
78
|
this.play();
|
|
69
79
|
})
|
|
70
80
|
.on('click', '.myplayer-video-mask', () => {
|
|
@@ -90,6 +100,10 @@ VideoPlayer.prototype.bindEvent = function() {
|
|
|
90
100
|
// 只有在显示进度条时才绑定进度条相关事件
|
|
91
101
|
if (this.options.showProgressBar) {
|
|
92
102
|
container
|
|
103
|
+
.on('dragstart', () => { console.log('video container dragstart') }, true)
|
|
104
|
+
.on('drag', () => { console.log('video container drag') }, true)
|
|
105
|
+
.on('dragend', () => { console.log('video container dragend') }, true)
|
|
106
|
+
.on('click', () => { console.log('video container click') }, true)
|
|
93
107
|
.on('dragstart', '.myplayer-progress', (e) => {
|
|
94
108
|
if (e.originalEvent) {
|
|
95
109
|
this.progressDragStart(e.originalEvent);
|
|
@@ -122,6 +136,11 @@ VideoPlayer.prototype.bindEvent = function() {
|
|
|
122
136
|
}
|
|
123
137
|
|
|
124
138
|
VideoPlayer.prototype.play = function() {
|
|
139
|
+
if (this.state.firstPlay) {
|
|
140
|
+
this.state.firstPlay = false;
|
|
141
|
+
this.$container.find('.myplayer-video-cover,.myplayer-video-preview').hide();
|
|
142
|
+
this.updateTotalTime();
|
|
143
|
+
}
|
|
125
144
|
const video = this.$container.find('video')[0];
|
|
126
145
|
video.play();
|
|
127
146
|
this.state.playing = true;
|
|
@@ -131,9 +150,11 @@ VideoPlayer.prototype.play = function() {
|
|
|
131
150
|
this.$container.find('.myplayer-progress').css('transform', 'none');
|
|
132
151
|
this.startUpdatingProgress();
|
|
133
152
|
this.hideControlsWithDelay();
|
|
153
|
+
this.options.stateChanged.call(this, 'play');
|
|
134
154
|
}
|
|
135
155
|
|
|
136
156
|
VideoPlayer.prototype.pause = function() {
|
|
157
|
+
this.showControls();
|
|
137
158
|
const video = this.$container.find('video')[0];
|
|
138
159
|
video.pause();
|
|
139
160
|
this.state.playing = false;
|
|
@@ -142,9 +163,26 @@ VideoPlayer.prototype.pause = function() {
|
|
|
142
163
|
this.$container.find('.myplayer-btn-pause').hide();
|
|
143
164
|
this.$container.find('.myplayer-progress').css('transform', 'scaleY(2)');
|
|
144
165
|
this.state.controlsDelayStart = Date.now();
|
|
166
|
+
this.options.stateChanged.call(this, 'pause');
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
VideoPlayer.prototype.stop = function() {
|
|
170
|
+
const video = this.$container.find('video')[0];
|
|
171
|
+
video.pause();
|
|
172
|
+
video.currentTime = 0;
|
|
173
|
+
this.state.playing = false;
|
|
174
|
+
this.$container.find('.myplayer-btn-play').show();
|
|
175
|
+
this.$container.find('.myplayer-btn-big-play').removeClass('myplayer-transparent');
|
|
176
|
+
this.$container.find('.myplayer-btn-pause').hide();
|
|
177
|
+
this.$container.find('.myplayer-progress').css('transform', 'scaleY(2)');
|
|
178
|
+
this.state.controlsDelayStart = Date.now();
|
|
179
|
+
this.$container.find('.myplayer-video-cover,.myplayer-video-preview').show();
|
|
180
|
+
this.state.firstPlay = true;
|
|
181
|
+
this.options.stateChanged.call(this, 'stop');
|
|
145
182
|
}
|
|
146
183
|
|
|
147
184
|
VideoPlayer.prototype.maskClicked = function() {
|
|
185
|
+
console.log('maskClicked')
|
|
148
186
|
if (this.state.controlsVisible === true) {
|
|
149
187
|
if (this.state.playing === true) {
|
|
150
188
|
this.pause();
|
|
@@ -152,7 +190,13 @@ VideoPlayer.prototype.maskClicked = function() {
|
|
|
152
190
|
this.play();
|
|
153
191
|
}
|
|
154
192
|
} else {
|
|
155
|
-
this.
|
|
193
|
+
if (this.options.clickToPause && this.state.playing === true) {
|
|
194
|
+
// 如果配置了点击直接暂停,且正在播放,则直接暂停
|
|
195
|
+
this.pause();
|
|
196
|
+
} else {
|
|
197
|
+
// 否则先展示控制条
|
|
198
|
+
this.showControls();
|
|
199
|
+
}
|
|
156
200
|
}
|
|
157
201
|
}
|
|
158
202
|
|
|
@@ -230,11 +274,37 @@ VideoPlayer.prototype.toggleFullScreen = function() {
|
|
|
230
274
|
bottom.removeClass('myplayer-full-screen');
|
|
231
275
|
fullScreenBtn.show();
|
|
232
276
|
exitFullScreenBtn.hide();
|
|
277
|
+
this.options.stateChanged.call(this, 'exitFullScreen');
|
|
233
278
|
} else {
|
|
234
279
|
innerContainer.addClass('myplayer-full-screen');
|
|
235
280
|
bottom.addClass('myplayer-full-screen');
|
|
236
281
|
fullScreenBtn.hide();
|
|
237
282
|
exitFullScreenBtn.show();
|
|
283
|
+
this.options.stateChanged.call(this, 'enterFullScreen');
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
this.hideControlsWithDelay();
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
VideoPlayer.prototype.setFullScreen = function (target = true) {
|
|
290
|
+
const $container = this.$container;
|
|
291
|
+
const fullScreenBtn = $container.find('.myplayer-btn-full-screen');
|
|
292
|
+
const exitFullScreenBtn = $container.find('.myplayer-btn-exit-full-screen');
|
|
293
|
+
const bottom = $container.find('.myplayer-bottom');
|
|
294
|
+
const innerContainer = $container.find('.myplayer-container');
|
|
295
|
+
|
|
296
|
+
if (!target && innerContainer.hasClass('myplayer-full-screen')) {
|
|
297
|
+
innerContainer.removeClass('myplayer-full-screen');
|
|
298
|
+
bottom.removeClass('myplayer-full-screen');
|
|
299
|
+
fullScreenBtn.show();
|
|
300
|
+
exitFullScreenBtn.hide();
|
|
301
|
+
this.options.stateChanged.call(this, 'exitFullScreen');
|
|
302
|
+
} else if (target && !innerContainer.hasClass('myplayer-full-screen')) {
|
|
303
|
+
innerContainer.addClass('myplayer-full-screen');
|
|
304
|
+
bottom.addClass('myplayer-full-screen');
|
|
305
|
+
fullScreenBtn.hide();
|
|
306
|
+
exitFullScreenBtn.show();
|
|
307
|
+
this.options.stateChanged.call(this, 'enterFullScreen');
|
|
238
308
|
}
|
|
239
309
|
|
|
240
310
|
this.hideControlsWithDelay();
|