xgplayer 3.0.8 → 3.0.9

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.
@@ -20,7 +20,7 @@
20
20
  * height?: number | string,
21
21
  * fluid?: boolean,
22
22
  * fitVideoSize?: 'fixWidth'|'fixHeight'|'fixed',
23
- * videoFillMode?: 'auto'|'fillHeight'|'fillWidth'|'fill'|'cover',
23
+ * videoFillMode?: 'auto'|'fillHeight'|'fillWidth'|'fill'|'cover'|'contain',
24
24
  * volume?: number | { [propName: string]: any },
25
25
  * autoplay?: boolean,
26
26
  * autoplayMuted?: boolean,
@@ -122,7 +122,7 @@ export type IPlayerOptions = {
122
122
  height?: number | string;
123
123
  fluid?: boolean;
124
124
  fitVideoSize?: 'fixWidth' | 'fixHeight' | 'fixed';
125
- videoFillMode?: 'auto' | 'fillHeight' | 'fillWidth' | 'fill' | 'cover';
125
+ videoFillMode?: 'auto' | 'fillHeight' | 'fillWidth' | 'fill' | 'cover' | 'contain';
126
126
  volume?: number | {
127
127
  [propName: string]: any;
128
128
  };
package/es/events.d.ts CHANGED
@@ -12,6 +12,7 @@ export const CANPLAY_THROUGH: "canplaythrough";
12
12
  export const DURATION_CHANGE: "durationchange";
13
13
  export const VOLUME_CHANGE: "volumechange";
14
14
  export const LOADED_DATA: "loadeddata";
15
+ export const LOADED_METADATA: "loadedmetadata";
15
16
  export const RATE_CHANGE: "ratechange";
16
17
  export const PROGRESS: "progress";
17
18
  export const LOAD_START: "loadstart";
package/es/events.js CHANGED
@@ -12,6 +12,7 @@ var CANPLAY_THROUGH = "canplaythrough";
12
12
  var DURATION_CHANGE = "durationchange";
13
13
  var VOLUME_CHANGE = "volumechange";
14
14
  var LOADED_DATA = "loadeddata";
15
+ var LOADED_METADATA = "loadedmetadata";
15
16
  var RATE_CHANGE = "ratechange";
16
17
  var PROGRESS = "progress";
17
18
  var LOAD_START = "loadstart";
@@ -51,11 +52,11 @@ var RESET = "reset";
51
52
  var SOURCE_ERROR = "source_error";
52
53
  var SOURCE_SUCCESS = "source_success";
53
54
  var SWITCH_SUBTITLE = "switch_subtitle";
54
- var VIDEO_EVENTS = ["play", "playing", "ended", "pause", "error", "seeking", "seeked", "timeupdate", "waiting", "canplay", "canplaythrough", "durationchange", "volumechange", "loadeddata", "ratechange", "progress", "loadstart", "emptied", "stalled", "suspend", "abort", "lowdecode"];
55
+ var VIDEO_EVENTS = ["play", "playing", "ended", "pause", "error", "seeking", "seeked", "timeupdate", "waiting", "canplay", "canplaythrough", "durationchange", "volumechange", "loadeddata", "loadedmetadata", "ratechange", "progress", "loadstart", "emptied", "stalled", "suspend", "abort", "lowdecode"];
55
56
  var STATS_EVENTS = {
56
57
  STATS_INFO: "stats_info",
57
58
  STATS_DOWNLOAD: "stats_download",
58
59
  STATS_RESET: "stats_reset"
59
60
  };
60
61
  var FPS_STUCK = "fps_stuck";
61
- export { ABORT, AFTER_DEFINITION_CHANGE, AUTOPLAY_PREVENTED, AUTOPLAY_STARTED, BEFORE_DEFINITION_CHANGE, BUFFER_CHANGE, CANPLAY, CANPLAY_THROUGH, COMPLETE, CSS_FULLSCREEN_CHANGE, DEFINITION_CHANGE, DESTROY, DOWNLOAD_SPEED_CHANGE, DURATION_CHANGE, EMPTIED, ENDED, ERROR, FPS_STUCK, FULLSCREEN_CHANGE, LOADED_DATA, LOAD_START, MINI_STATE_CHANGE, PAUSE, PIP_CHANGE, PLAY, PLAYER_BLUR, PLAYER_FOCUS, PLAYING, PLAYNEXT, PROGRESS, RATE_CHANGE, READY, REPLAY, RESET, RETRY, ROTATE, SCREEN_SHOT, SEEKED, SEEKING, SEI_PARSED, SHORTCUT, SOURCE_ERROR, SOURCE_SUCCESS, STALLED, STATS_EVENTS, SUSPEND, SWITCH_SUBTITLE, TIME_UPDATE, URL_CHANGE, URL_NULL, USER_ACTION, VIDEO_EVENTS, VIDEO_RESIZE, VOLUME_CHANGE, WAITING, XGLOG };
62
+ export { ABORT, AFTER_DEFINITION_CHANGE, AUTOPLAY_PREVENTED, AUTOPLAY_STARTED, BEFORE_DEFINITION_CHANGE, BUFFER_CHANGE, CANPLAY, CANPLAY_THROUGH, COMPLETE, CSS_FULLSCREEN_CHANGE, DEFINITION_CHANGE, DESTROY, DOWNLOAD_SPEED_CHANGE, DURATION_CHANGE, EMPTIED, ENDED, ERROR, FPS_STUCK, FULLSCREEN_CHANGE, LOADED_DATA, LOADED_METADATA, LOAD_START, MINI_STATE_CHANGE, PAUSE, PIP_CHANGE, PLAY, PLAYER_BLUR, PLAYER_FOCUS, PLAYING, PLAYNEXT, PROGRESS, RATE_CHANGE, READY, REPLAY, RESET, RETRY, ROTATE, SCREEN_SHOT, SEEKED, SEEKING, SEI_PARSED, SHORTCUT, SOURCE_ERROR, SOURCE_SUCCESS, STALLED, STATS_EVENTS, SUSPEND, SWITCH_SUBTITLE, TIME_UPDATE, URL_CHANGE, URL_NULL, USER_ACTION, VIDEO_EVENTS, VIDEO_RESIZE, VOLUME_CHANGE, WAITING, XGLOG };
package/es/index.css CHANGED
@@ -131,6 +131,10 @@
131
131
  height: 100%;
132
132
  outline: none;
133
133
  }
134
+ .xgplayer[data-xgfill=contain] video {
135
+ -o-object-fit: contain;
136
+ object-fit: contain;
137
+ }
134
138
  .xgplayer[data-xgfill=cover] video {
135
139
  -o-object-fit: cover;
136
140
  object-fit: cover;
@@ -127,6 +127,7 @@ declare class MediaProxy {
127
127
  * @private
128
128
  */
129
129
  private _videoSourceCount;
130
+ _videoSourceIndex: number;
130
131
  _vLoadeddata: (e: any) => void;
131
132
  _sourceError: (e: any) => void;
132
133
  /**
package/es/mediaProxy.js CHANGED
@@ -182,10 +182,11 @@ var MediaProxy = /* @__PURE__ */ function(_EventEmitter) {
182
182
  var _this6 = this;
183
183
  video.removeAttribute("src");
184
184
  video.load();
185
- urls.forEach(function(item) {
185
+ urls.forEach(function(item, index) {
186
186
  _this6.media.appendChild(util.createDom("source", "", {
187
187
  src: "".concat(item.src),
188
- type: "".concat(item.type || "")
188
+ type: "".concat(item.type || ""),
189
+ "data-index": index + 1
189
190
  }));
190
191
  });
191
192
  var _c = video.children;
@@ -193,6 +194,7 @@ var MediaProxy = /* @__PURE__ */ function(_EventEmitter) {
193
194
  return;
194
195
  }
195
196
  this._videoSourceCount = _c.length;
197
+ this._videoSourceIndex = _c.length;
196
198
  this._vLoadeddata = function(e) {
197
199
  _this6.emit(SOURCE_SUCCESS, {
198
200
  src: e.target.currentSrc,
@@ -207,8 +209,9 @@ var MediaProxy = /* @__PURE__ */ function(_EventEmitter) {
207
209
  }
208
210
  }
209
211
  !this._sourceError && (this._sourceError = function(e) {
210
- _this6._videoSourceCount--;
211
- if (_this6._videoSourceCount === 0) {
212
+ var _dIndex = parseInt(e.target.getAttribute("data-index"), 10);
213
+ _this6._videoSourceIndex--;
214
+ if (_this6._videoSourceIndex === 0 || _dIndex >= _this6._videoSourceCount) {
212
215
  var _err = {
213
216
  code: 4,
214
217
  message: "sources_load_error"
package/es/player.d.ts CHANGED
@@ -167,6 +167,12 @@ declare class Player extends MediaProxy {
167
167
  vy: number;
168
168
  vx: number;
169
169
  };
170
+ sizeInfo: {
171
+ width: number;
172
+ height: number;
173
+ left: number;
174
+ top: number;
175
+ };
170
176
  /**
171
177
  * @private
172
178
  * @type { { t: number, acc:number, acc: number, loopAcc: number, [propName: string]: any;} }
@@ -482,12 +488,14 @@ declare class Player extends MediaProxy {
482
488
  * @description 播放器焦点状态,控制栏显示
483
489
  * @param { {
484
490
  * autoHide?: boolean, // 是否可以自动隐藏
485
- * delay?: number // 自动隐藏的延迟时间, ms, 不传默认使用3000ms
491
+ * delay?: number // 自动隐藏的延迟时间, ms, 不传默认使用3000ms
492
+ * isLock?: boolean // 是否锁定, 锁定之后自动呼出和blur调用都不生效, 默认值false
486
493
  * } } [data]
487
494
  */
488
495
  focus(data?: {
489
496
  autoHide?: boolean;
490
497
  delay?: number;
498
+ isLock?: boolean;
491
499
  }): void;
492
500
  /**
493
501
  * @description 取消播放器当前焦点状态
@@ -498,12 +506,13 @@ declare class Player extends MediaProxy {
498
506
  }): void;
499
507
  /**
500
508
  * @protected
501
- * @param { { autoHide?: boolean, delay?: number} } [data]
509
+ * @param { { autoHide?: boolean, delay?: number, isLock?: boolean } } [data]
502
510
  * @returns
503
511
  */
504
- protected onFocus({ autoHide, delay }?: {
512
+ protected onFocus(data?: {
505
513
  autoHide?: boolean;
506
514
  delay?: number;
515
+ isLock?: boolean;
507
516
  }): void;
508
517
  /**
509
518
  * @protected
package/es/player.js CHANGED
@@ -160,6 +160,12 @@ var Player = /* @__PURE__ */ function(_MediaProxy) {
160
160
  vy: 0,
161
161
  vx: 0
162
162
  };
163
+ _this.sizeInfo = {
164
+ width: 0,
165
+ height: 0,
166
+ left: 0,
167
+ top: 0
168
+ };
163
169
  _this._accPlayed = {
164
170
  t: 0,
165
171
  acc: 0,
@@ -262,16 +268,16 @@ var Player = /* @__PURE__ */ function(_MediaProxy) {
262
268
  this.addClass(STATE_CLASS.NO_START);
263
269
  }
264
270
  if (this.config.fluid) {
265
- var _this$config3 = this.config, width = _this$config3.width, height = _this$config3.height;
266
- if (typeof width !== "number" || typeof height !== "number") {
267
- width = 600;
268
- height = 337.5;
271
+ var _this$config3 = this.config, _width = _this$config3.width, _height = _this$config3.height;
272
+ if (typeof _width !== "number" || typeof _height !== "number") {
273
+ _width = 600;
274
+ _height = 337.5;
269
275
  }
270
276
  var style = {
271
277
  width: "100%",
272
278
  height: "0",
273
279
  "max-width": "100%",
274
- "padding-top": "".concat(height * 100 / width, "%")
280
+ "padding-top": "".concat(_height * 100 / _width, "%")
275
281
  };
276
282
  Object.keys(style).forEach(function(key) {
277
283
  _this2.root.style[key] = style[key];
@@ -287,6 +293,11 @@ var Player = /* @__PURE__ */ function(_MediaProxy) {
287
293
  }
288
294
  });
289
295
  }
296
+ var _this$root$getBoundin = this.root.getBoundingClientRect(), width = _this$root$getBoundin.width, height = _this$root$getBoundin.height, left = _this$root$getBoundin.left, top = _this$root$getBoundin.top;
297
+ this.sizeInfo.width = width;
298
+ this.sizeInfo.height = height;
299
+ this.sizeInfo.left = left;
300
+ this.sizeInfo.top = top;
290
301
  return true;
291
302
  }
292
303
  }, {
@@ -1014,7 +1025,7 @@ var Player = /* @__PURE__ */ function(_MediaProxy) {
1014
1025
  var fullEl = util.getFullScreenEl();
1015
1026
  if (fullEl === this._fullscreenEl) {
1016
1027
  this.onFullscreenChange();
1017
- return;
1028
+ return Promise.resolve();
1018
1029
  }
1019
1030
  try {
1020
1031
  for (var i = 0; i < GET_FULLSCREEN_API.length; i++) {
@@ -1187,29 +1198,33 @@ var Player = /* @__PURE__ */ function(_MediaProxy) {
1187
1198
  key: "onFocus",
1188
1199
  value: function onFocus() {
1189
1200
  var _this21 = this;
1190
- var _ref = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}, _ref$autoHide = _ref.autoHide, autoHide = _ref$autoHide === void 0 ? !this.config.closePlayerBlur : _ref$autoHide, _ref$delay = _ref.delay, delay = _ref$delay === void 0 ? this.config.inactive : _ref$delay;
1201
+ var data = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {
1202
+ autoHide: true,
1203
+ delay: 3e3
1204
+ };
1191
1205
  this.isActive = true;
1192
1206
  this.removeClass(STATE_CLASS.INACTIVE);
1193
1207
  if (this.userTimer) {
1194
1208
  util.clearTimeout(this, this.userTimer);
1195
1209
  this.userTimer = null;
1196
1210
  }
1197
- if (!autoHide) {
1211
+ if (data.autoHide === false || data.isLock === true) {
1198
1212
  if (this.userTimer) {
1199
1213
  util.clearTimeout(this, this.userTimer);
1200
1214
  this.userTimer = null;
1201
1215
  }
1202
1216
  return;
1203
1217
  }
1218
+ var time = data.delay || this.config.inactive;
1204
1219
  this.userTimer = util.setTimeout(this, function() {
1205
1220
  _this21.userTimer = null;
1206
1221
  _this21.blur();
1207
- }, delay);
1222
+ }, time);
1208
1223
  }
1209
1224
  }, {
1210
1225
  key: "onBlur",
1211
1226
  value: function onBlur() {
1212
- var _ref2 = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}, _ref2$ignorePaused = _ref2.ignorePaused, ignorePaused = _ref2$ignorePaused === void 0 ? false : _ref2$ignorePaused;
1227
+ var _ref = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}, _ref$ignorePaused = _ref.ignorePaused, ignorePaused = _ref$ignorePaused === void 0 ? false : _ref$ignorePaused;
1213
1228
  if (!this.isActive) {
1214
1229
  return;
1215
1230
  }
@@ -1333,7 +1348,7 @@ var Player = /* @__PURE__ */ function(_MediaProxy) {
1333
1348
  }, {
1334
1349
  key: "onTimeupdate",
1335
1350
  value: function onTimeupdate() {
1336
- !this._videoHeight && this.resize();
1351
+ !this._videoHeight && this.media.videoHeight && this.resize();
1337
1352
  if ((this.waitTimer || this.hasClass(STATE_CLASS.LOADING)) && this.media.readyState > 2) {
1338
1353
  this.removeClass(STATE_CLASS.LOADING);
1339
1354
  util.clearTimeout(this, this.waitTimer);
@@ -1408,8 +1423,11 @@ var Player = /* @__PURE__ */ function(_MediaProxy) {
1408
1423
  key: "resizePosition",
1409
1424
  value: function resizePosition() {
1410
1425
  var _this$videoPos = this.videoPos, rotate = _this$videoPos.rotate, vy = _this$videoPos.vy, vx = _this$videoPos.vx, h = _this$videoPos.h, w = _this$videoPos.w;
1426
+ if (!rotate && !vy && !vx) {
1427
+ return;
1428
+ }
1411
1429
  var _pi = this.videoPos._pi;
1412
- if (!_pi) {
1430
+ if (!_pi && this.media.videoHeight) {
1413
1431
  _pi = this.media.videoWidth / this.media.videoHeight * 100;
1414
1432
  }
1415
1433
  if (!_pi) {
@@ -1509,9 +1527,14 @@ var Player = /* @__PURE__ */ function(_MediaProxy) {
1509
1527
  if (!this.media) {
1510
1528
  return;
1511
1529
  }
1530
+ var containerSize = this.root.getBoundingClientRect();
1531
+ this.sizeInfo.width = containerSize.width;
1532
+ this.sizeInfo.height = containerSize.height;
1533
+ this.sizeInfo.left = containerSize.left;
1534
+ this.sizeInfo.top = containerSize.top;
1512
1535
  var _this$media = this.media, videoWidth = _this$media.videoWidth, videoHeight = _this$media.videoHeight;
1513
1536
  var _this$config6 = this.config, fitVideoSize = _this$config6.fitVideoSize, videoFillMode = _this$config6.videoFillMode;
1514
- if (videoFillMode === "fill" || videoFillMode === "cover") {
1537
+ if (videoFillMode === "fill" || videoFillMode === "cover" || videoFillMode === "contain") {
1515
1538
  this.setAttribute("data-xgfill", videoFillMode);
1516
1539
  }
1517
1540
  if (!videoHeight || !videoWidth) {
@@ -1519,7 +1542,6 @@ var Player = /* @__PURE__ */ function(_MediaProxy) {
1519
1542
  }
1520
1543
  this._videoHeight = videoHeight;
1521
1544
  this._videoWidth = videoWidth;
1522
- var containerSize = this.root.getBoundingClientRect();
1523
1545
  var controlsHeight = this.controls && this.innerContainer ? this.controls.root.getBoundingClientRect().height : 0;
1524
1546
  var width = containerSize.width;
1525
1547
  var height = containerSize.height - controlsHeight;
@@ -42,7 +42,7 @@ declare class Controls extends Plugin {
42
42
  */
43
43
  readonly innerRoot: HTMLElement;
44
44
  onMouseEnter: (e: any) => void;
45
- onMouseLeave: () => void;
45
+ onMouseLeave: (e: any) => void;
46
46
  focus(): void;
47
47
  focusAwhile(): void;
48
48
  blur(): void;
@@ -21,7 +21,7 @@ var Controls = /* @__PURE__ */ function(_Plugin) {
21
21
  autoHide: false
22
22
  });
23
23
  });
24
- _defineProperty(_assertThisInitialized(_this), "onMouseLeave", function() {
24
+ _defineProperty(_assertThisInitialized(_this), "onMouseLeave", function(e) {
25
25
  var _assertThisInitialize2 = _assertThisInitialized(_this), player = _assertThisInitialize2.player;
26
26
  player.focus();
27
27
  });
@@ -99,12 +99,13 @@ var Controls = /* @__PURE__ */ function(_Plugin) {
99
99
  }, {
100
100
  key: "show",
101
101
  value: function show() {
102
- util.addClass(this.root, "show");
102
+ this.root.style.display = "";
103
+ this.player.focus();
103
104
  }
104
105
  }, {
105
106
  key: "hide",
106
107
  value: function hide() {
107
- util.removeClass(this.root, "show");
108
+ this.root.style.display = "none";
108
109
  }
109
110
  }, {
110
111
  key: "mode",
@@ -8,6 +8,7 @@ export type IKeyboardConfig = {
8
8
  [propName: string]: any;
9
9
  };
10
10
  disable: boolean;
11
+ playbackRate: number;
11
12
  isIgnoreUserActive: boolean;
12
13
  };
13
14
  declare class Keyboard extends BasePlugin {
@@ -22,47 +23,66 @@ declare class Keyboard extends BasePlugin {
22
23
  keyCode: number;
23
24
  action: string;
24
25
  disable: boolean;
26
+ disablePress: boolean;
25
27
  noBodyTarget: boolean;
26
28
  };
27
29
  up: {
28
30
  keyCode: number;
29
31
  action: string;
30
32
  disable: boolean;
33
+ disablePress: boolean;
31
34
  noBodyTarget: boolean;
32
35
  };
33
36
  down: {
34
37
  keyCode: number;
35
38
  action: string;
36
39
  disable: boolean;
40
+ disablePress: boolean;
37
41
  noBodyTarget: boolean;
38
42
  };
39
43
  left: {
40
44
  keyCode: number;
41
45
  action: string;
46
+ disablePress: boolean;
42
47
  disable: boolean;
43
48
  };
44
49
  right: {
45
50
  keyCode: number;
46
51
  action: string;
52
+ pressAction: string;
53
+ disablePress: boolean;
47
54
  disable: boolean;
48
55
  };
49
56
  esc: {
50
57
  keyCode: number;
51
58
  action: string;
59
+ disablePress: boolean;
52
60
  disable: boolean;
53
61
  };
54
62
  };
63
+ _keyState: {
64
+ isKeyDown: boolean;
65
+ isBodyKeyDown: boolean;
66
+ isPress: boolean;
67
+ tt: number;
68
+ playbackRate: number;
69
+ };
55
70
  checkIsVisible(): boolean;
56
71
  checkCode(code: any, isBodyTarget: any): boolean;
57
72
  downVolume(event: any): void;
58
73
  upVolume(event: any): void;
59
74
  seek(event: any): void;
60
75
  seekBack(event: any): void;
76
+ changePlaybackRate(event: any): void;
61
77
  playPause(event: any): void;
62
78
  exitFullscreen(event: any): void;
63
- onBodyKeyDown: (event: any) => boolean;
64
- onKeydown: (event: any) => boolean;
65
- handleKeyCode(curKeyCode: any, event: any): void;
79
+ onBodyKeyDown: (event: any) => void;
80
+ onBodyKeyUp: (event: any) => void;
81
+ onKeydown: (event: any) => void;
82
+ onKeyup: (event: any) => void;
83
+ handleKeyDown(e: any): void;
84
+ handleKeyUp(e: any): void;
85
+ handleKeyCode(curKeyCode: any, event: any, isPress: any): void;
66
86
  disable(): void;
67
87
  enable(): void;
68
88
  }