tencent.jquery.pix.component 1.0.69 → 1.0.71

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.
@@ -2,6 +2,9 @@
2
2
  display: flex;
3
3
  flex-direction: row;
4
4
  height: 100%;
5
+ position: absolute;
6
+ left: 0;
7
+ top: 0;
5
8
  }
6
9
 
7
10
  .banner-pagination-item {
@@ -43,4 +46,4 @@
43
46
  text-wrap: nowrap;
44
47
  overflow: hidden;
45
48
  color: white;
46
- }
49
+ }
@@ -15,6 +15,7 @@ import './videocss.scss'
15
15
  * @param {string} options.vid 腾讯视频id
16
16
  * @param {string} [options.videoUrl] 视频地址,非腾讯视频时使用,比如上传到cos的视频
17
17
  * @param {string} [options.previewUrl] 视频预览图
18
+ * @param {string} [options.timeUnit] 视频的时间单位 默认是s秒 ,如果是ms,则传1000
18
19
  * @param {0|1} [options.videoType=1] 视频类型选项,0: 标清,1: 高清
19
20
  * @param {number} [options.autoHideControlsDelayMs=5000] 自动隐藏控制条延迟时间,单位ms
20
21
  * @param {boolean} [options.showProgressBar=true] 是否显示进度条
@@ -24,18 +25,25 @@ import './videocss.scss'
24
25
  export function VideoPlayer(options) {
25
26
  this.options = options
26
27
  if (typeof this.options.stateChanged !== 'function') {
27
- this.options.stateChanged = () => {};
28
+ this.options.stateChanged = () => { };
28
29
  }
29
30
  this.init()
30
31
  }
31
32
 
32
- VideoPlayer.prototype.init = async function() {
33
- if (windowEnv === 'h5') {
34
- this.durationFactor = 1; // 浏览器,单位s
33
+ VideoPlayer.prototype.init = async function () {
34
+ if ('timeUnit' in this.options) {
35
+ // 浏览器,单位s ; PixUI,单位ms
36
+ this.timeUnit = Number(this.options.timeUnit) || 1;
35
37
  } else {
36
- this.durationFactor = 1000; // PixUI,单位ms
38
+ if (windowEnv === 'pix') {
39
+ this.timeUnit = 1000;
40
+ } else {
41
+ this.timeUnit = 1;
42
+ }
37
43
  }
38
44
 
45
+
46
+
39
47
  const $container = $(this.options.container);
40
48
  this.$container = $container;
41
49
  $container.html(VideoHTML);
@@ -81,7 +89,7 @@ VideoPlayer.prototype.init = async function() {
81
89
  this.bindEvent();
82
90
  }
83
91
 
84
- VideoPlayer.prototype.bindEvent = function() {
92
+ VideoPlayer.prototype.bindEvent = function () {
85
93
  const container = this.$container;
86
94
  container.off()
87
95
  .on('click', '.myplayer-video-cover', () => {
@@ -157,7 +165,7 @@ VideoPlayer.prototype.bindEvent = function() {
157
165
  }
158
166
  }
159
167
 
160
- VideoPlayer.prototype.play = function() {
168
+ VideoPlayer.prototype.play = function () {
161
169
  if (this.state.firstPlay) {
162
170
  this.state.firstPlay = false;
163
171
  this.$container.find('.myplayer-video-cover,.myplayer-video-preview').hide();
@@ -175,7 +183,7 @@ VideoPlayer.prototype.play = function() {
175
183
  this.options.stateChanged.call(this, 'play');
176
184
  }
177
185
 
178
- VideoPlayer.prototype.pause = function() {
186
+ VideoPlayer.prototype.pause = function () {
179
187
  this.showControls();
180
188
  const video = this.$container.find('video')[0];
181
189
  video.pause();
@@ -188,8 +196,8 @@ VideoPlayer.prototype.pause = function() {
188
196
  this.options.stateChanged.call(this, 'pause');
189
197
  }
190
198
 
191
- VideoPlayer.prototype.stop = function() {
192
- console.log('stop');
199
+ VideoPlayer.prototype.stop = function () {
200
+
193
201
  const video = this.$container.find('video')[0];
194
202
  video.pause();
195
203
  video.currentTime = 0;
@@ -204,8 +212,8 @@ VideoPlayer.prototype.stop = function() {
204
212
  this.options.stateChanged.call(this, 'stop');
205
213
  }
206
214
 
207
- VideoPlayer.prototype.maskClicked = function() {
208
- console.log('maskClicked')
215
+ VideoPlayer.prototype.maskClicked = function () {
216
+
209
217
  if (this.state.controlsVisible === true) {
210
218
  if (this.state.playing === true) {
211
219
  this.pause();
@@ -223,7 +231,7 @@ VideoPlayer.prototype.maskClicked = function() {
223
231
  }
224
232
  }
225
233
 
226
- VideoPlayer.prototype.showControls = function() {
234
+ VideoPlayer.prototype.showControls = function () {
227
235
  const container = this.$container;
228
236
  container.find('.myplayer-video-mask').removeClass('myplayer-transparent');
229
237
  container.find('.myplayer-top').removeClass('myplayer-transparent');
@@ -236,7 +244,7 @@ VideoPlayer.prototype.showControls = function() {
236
244
  this.hideControlsWithDelay();
237
245
  }
238
246
 
239
- VideoPlayer.prototype.hideControls = function() {
247
+ VideoPlayer.prototype.hideControls = function () {
240
248
  const container = this.$container;
241
249
  container.find('.myplayer-video-mask').addClass('myplayer-transparent');
242
250
  container.find('.myplayer-top').addClass('myplayer-transparent');
@@ -245,7 +253,7 @@ VideoPlayer.prototype.hideControls = function() {
245
253
  this.state.updatingProgress = false;
246
254
  }
247
255
 
248
- VideoPlayer.prototype.hideControlsWithDelay = function() {
256
+ VideoPlayer.prototype.hideControlsWithDelay = function () {
249
257
  this.state.controlsDelayStart = Date.now();
250
258
  setTimeout(() => {
251
259
  const nowTime = Date.now();
@@ -258,7 +266,7 @@ VideoPlayer.prototype.hideControlsWithDelay = function() {
258
266
  }, this.options.autoHideControlsDelayMs);
259
267
  }
260
268
 
261
- VideoPlayer.prototype.startUpdatingProgress = function() {
269
+ VideoPlayer.prototype.startUpdatingProgress = function () {
262
270
  this.updateProgress();
263
271
 
264
272
  if (this.state.updatingProgress) {
@@ -266,13 +274,13 @@ VideoPlayer.prototype.startUpdatingProgress = function() {
266
274
  }
267
275
  }
268
276
 
269
- VideoPlayer.prototype.updateProgress = function() {
277
+ VideoPlayer.prototype.updateProgress = function () {
270
278
  const video = this.$container.find('video')[0];
271
279
  if (!video) return;
272
-
280
+
273
281
  const currentTime = video.currentTime || 0;
274
282
  const duration = video.duration || 0;
275
-
283
+
276
284
  // 防止duration为NaN或0时计算出错
277
285
  if (duration && !isNaN(duration) && duration > 0) {
278
286
  const progress = currentTime / duration;
@@ -286,23 +294,22 @@ VideoPlayer.prototype.updateProgress = function() {
286
294
  }
287
295
 
288
296
  // 格式化当前播放时间(currentTime单位为秒)
289
- this.$container.find('.myplayer-playtime').html(formatTime(currentTime));
297
+ this.$container.find('.myplayer-playtime').html(this.formatTime(currentTime));
290
298
  }
291
299
 
292
- VideoPlayer.prototype.updateTotalTime = function() {
300
+ VideoPlayer.prototype.updateTotalTime = function () {
293
301
  const video = this.$container.find('video')[0];
294
302
  if (!video) return;
295
-
296
303
  const duration = video.duration;
297
-
304
+
298
305
  // 只有当duration有效时才更新显示
299
306
  if (duration && !isNaN(duration) && isFinite(duration) && duration > 0) {
300
307
  // duration单位为秒
301
- this.$container.find('.myplayer-totaltime').html(formatTime(duration));
308
+ this.$container.find('.myplayer-totaltime').html(this.formatTime(duration));
302
309
  }
303
310
  }
304
311
 
305
- VideoPlayer.prototype.toggleFullScreen = function() {
312
+ VideoPlayer.prototype.toggleFullScreen = function () {
306
313
  const $container = this.$container;
307
314
  const fullScreenBtn = $container.find('.myplayer-btn-full-screen');
308
315
  const exitFullScreenBtn = $container.find('.myplayer-btn-exit-full-screen');
@@ -366,15 +373,15 @@ VideoPlayer.prototype.setFullScreen = function (target = true) {
366
373
  * 将容器移动到body(进入全屏时调用)
367
374
  * @private
368
375
  */
369
- VideoPlayer.prototype._moveToBody = function() {
376
+ VideoPlayer.prototype._moveToBody = function () {
370
377
  const containerEl = this.$container[0];
371
-
378
+
372
379
  // 保存原始位置信息(仅在第一次移动时保存)
373
380
  if (!this.state.originalParent) {
374
381
  this.state.originalParent = containerEl.parentNode;
375
382
  this.state.originalNextSibling = containerEl.nextSibling;
376
383
  }
377
-
384
+
378
385
  // 从原容器解绑
379
386
  this.$container.off();
380
387
  // 从body解绑所有相关事件
@@ -383,10 +390,10 @@ VideoPlayer.prototype._moveToBody = function() {
383
390
  $(document.body).off('dragstart.myplayer');
384
391
  $(document.body).off('drag.myplayer');
385
392
  $(document.body).off('dragend.myplayer');
386
-
393
+
387
394
  // 移动到body
388
395
  document.body.appendChild(containerEl);
389
-
396
+
390
397
  // 重新绑定事件
391
398
  this.bindEvent();
392
399
  }
@@ -395,24 +402,24 @@ VideoPlayer.prototype._moveToBody = function() {
395
402
  * 将容器移回原位置(退出全屏时调用)
396
403
  * @private
397
404
  */
398
- VideoPlayer.prototype._moveBackToOriginal = function() {
405
+ VideoPlayer.prototype._moveBackToOriginal = function () {
399
406
  const containerEl = this.$container[0];
400
-
407
+
401
408
  // 如果没有保存原始位置,说明还没移动过,直接返回
402
409
  if (!this.state.originalParent) {
403
410
  return;
404
411
  }
405
-
412
+
406
413
  // 解绑事件
407
414
  this.$container.off();
408
-
415
+
409
416
  // 移回原位置
410
417
  if (this.state.originalNextSibling) {
411
418
  this.state.originalParent.insertBefore(containerEl, this.state.originalNextSibling);
412
419
  } else {
413
420
  this.state.originalParent.appendChild(containerEl);
414
421
  }
415
-
422
+
416
423
  // 重新绑定事件
417
424
  this.bindEvent();
418
425
  }
@@ -421,11 +428,11 @@ VideoPlayer.prototype._moveBackToOriginal = function() {
421
428
  * 进度条拖动开始
422
429
  * @param {MouseEvent} e
423
430
  */
424
- VideoPlayer.prototype.progressDragStart = function(e) {
431
+ VideoPlayer.prototype.progressDragStart = function (e) {
425
432
  if (!this.options.showProgressBar) {
426
433
  return;
427
434
  }
428
-
435
+
429
436
  this.state.updatingProgress = false;
430
437
  if (this.state.playing === true) {
431
438
  this.pause();
@@ -436,11 +443,11 @@ VideoPlayer.prototype.progressDragStart = function(e) {
436
443
  * 进度条拖动
437
444
  * @param {MouseEvent} e
438
445
  */
439
- VideoPlayer.prototype.progressDrag = function(e) {
446
+ VideoPlayer.prototype.progressDrag = function (e) {
440
447
  if (!this.options.showProgressBar) {
441
448
  return;
442
449
  }
443
-
450
+
444
451
  const $container = this.$container;
445
452
  const progress = $container.find('.myplayer-progress');
446
453
  const subprogress = $container.find('.myplayer-subprogress');
@@ -451,63 +458,86 @@ VideoPlayer.prototype.progressDrag = function(e) {
451
458
  const rect = progress[0].getBoundingClientRect();
452
459
  const clientX = e.clientX !== undefined ? e.clientX : (e.touches ? e.touches[0].clientX : 0);
453
460
  const curOffset = Math.max(Math.min(clientX - rect.left, parentWidth), 0);
454
-
461
+
455
462
  subprogress.width(`${curOffset}px`);
456
463
  const adjustedPlayTime = curOffset / parentWidth * video.duration;
457
- $container.find('.myplayer-playtime').html(formatTime(adjustedPlayTime));
464
+ $container.find('.myplayer-playtime').html(this.formatTime(adjustedPlayTime));
458
465
  }
459
466
 
460
467
  /**
461
468
  * 进度条拖动结束
462
469
  * @param {MouseEvent} e
463
470
  */
464
- VideoPlayer.prototype.progressDragEnd = function(e) {
471
+ VideoPlayer.prototype.progressDragEnd = function (e) {
465
472
  if (!this.options.showProgressBar) {
466
473
  return;
467
474
  }
468
-
475
+
469
476
  const $container = this.$container;
470
477
  const video = $container.find('video')[0];
471
478
  const progress = $container.find('.myplayer-progress');
472
479
  const parentWidth = progress.width();
473
-
480
+
474
481
  // 使用getBoundingClientRect计算准确的点击位置
475
482
  const rect = progress[0].getBoundingClientRect();
476
483
  const clientX = e.clientX !== undefined ? e.clientX : (e.touches ? e.touches[0].clientX : 0);
477
484
  const curOffset = Math.max(Math.min(clientX - rect.left, parentWidth), 0);
478
-
485
+
486
+ const duration = video.duration;//this.getCurrentDuration();
479
487
  // 计算目标播放时间(单位:秒)
480
- const targetTime = (curOffset / parentWidth) * video.duration;
481
-
488
+ const targetTime = (curOffset / parentWidth) * duration;
489
+
482
490
  // 确保duration有效再设置currentTime
483
- if (video.duration && !isNaN(video.duration) && video.duration > 0) {
484
- video.currentTime = targetTime;
491
+ if (duration && !isNaN(duration) && duration > 0) {
492
+
493
+ // 这里的currentTime单位为秒
494
+ video.currentTime = this.getCurrentDuration(targetTime);
485
495
  }
486
496
 
487
497
  this.play();
488
-
498
+
489
499
  this.state.updatingProgress = true;
490
500
  this.startUpdatingProgress();
491
501
  }
492
502
 
503
+ // 格式化时间
504
+ VideoPlayer.prototype.formatTime = function (duration) {
505
+ let secs = duration;
506
+ if (this.timeUnit !== 1) {
507
+ secs = secs / this.timeUnit;
508
+ }
509
+ const minutes = Math.floor(secs / 60);
510
+ const seconds = Math.floor(secs % 60);
511
+ return `${minutes < 10 ? '0' : ''}${minutes}:${seconds < 10 ? '0' : ''}${seconds}`;
512
+ }
513
+
514
+ // 获取当前的视频时间
515
+ VideoPlayer.prototype.getCurrentDuration = function (duration) {
516
+ let secs = duration;
517
+ if (this.timeUnit !== 1) {
518
+ secs = secs / this.timeUnit;
519
+ }
520
+ return secs;
521
+ }
522
+
493
523
  /**
494
524
  * 获取视频真实地址
495
525
  * @param {string} vid 腾讯视频vid
496
526
  * @param {0|1} [type] 类型,0: 标清,1: 高清
497
527
  * @returns {Promise<string>} 真实视频地址
498
528
  */
499
- const getVideoURL = async function(vid, type = 1) {
529
+ const getVideoURL = async function (vid, type = 1) {
500
530
  const sApiUrl = `https://vv.video.qq.com/getinfo?vid=${vid}&platform=101001&charge=0&otype=json&t=${Date.now()}`;
501
531
 
502
532
  try {
503
- console.log('processing vid through sApiUrl: ', sApiUrl);
533
+
504
534
  const res = await fetchData(sApiUrl);
505
- console.log('222 processing vid through sApiUrl: ', sApiUrl);
535
+
506
536
  const processedStr = res.replace('QZOutputJson=', '');
507
537
  const jsonStr = processedStr.substring(0, processedStr.length - 1);
508
538
  const resObj = JSON.parse(jsonStr);
509
539
  const sRealUrl = `${resObj.vl.vi[0].ul.ui[type].url}${resObj.vl.vi[0].fn}?vkey=${resObj.vl.vi[0].fvkey}`;
510
- console.log('腾讯视频真实地址: ', sRealUrl);
540
+
511
541
  return sRealUrl;
512
542
  } catch (err) {
513
543
  console.error(err)
@@ -520,7 +550,7 @@ const getVideoURL = async function(vid, type = 1) {
520
550
  * @param {string} url
521
551
  * @returns {Promise<string>}
522
552
  */
523
- const fetchData = function(url) {
553
+ const fetchData = function (url) {
524
554
  const xhr = new XMLHttpRequest();
525
555
  xhr.open('GET', url);
526
556
  xhr.send();
@@ -538,8 +568,3 @@ const fetchData = function(url) {
538
568
  });
539
569
  }
540
570
 
541
- const formatTime = function(secs) {
542
- const minutes = Math.floor(secs / 60);
543
- const seconds = Math.floor(secs % 60);
544
- return `${minutes < 10 ? '0' : ''}${minutes}:${seconds < 10 ? '0' : ''}${seconds}`;
545
- }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tencent.jquery.pix.component",
3
- "version": "1.0.69",
3
+ "version": "1.0.71",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "files": [