xgplayer 3.1.0-alpha.0 → 3.1.0-alpha.2
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/CHANGELOG.md +11 -1
- package/dist/index.min.css +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/es/constant.d.ts +0 -4
- package/es/constant.js +4 -1
- package/es/defaultConfig.js +2 -0
- package/es/error.js +2 -2
- package/es/index.d.ts +2 -1
- package/es/index.js +4 -3
- package/es/index.umd.d.ts +60 -1
- package/es/index.umd.js +29 -1
- package/es/lang/i18n.js +4 -4
- package/es/mediaProxy.d.ts +8 -0
- package/es/mediaProxy.js +13 -8
- package/es/player.d.ts +119 -14
- package/es/player.js +669 -163
- package/es/plugin/basePlugin.d.ts +6 -3
- package/es/plugin/basePlugin.js +6 -5
- package/es/plugin/index.d.ts +2 -1
- package/es/plugin/plugin.d.ts +0 -1
- package/es/plugin/plugin.js +11 -11
- package/es/plugin/pluginsManager.d.ts +14 -0
- package/es/plugin/pluginsManager.js +32 -16
- package/es/plugin/resizeObserver.js +1 -1
- package/es/plugins/common/iconPlugin.js +1 -0
- package/es/plugins/common/optionList.js +10 -10
- package/es/plugins/common/optionsIcon.js +13 -9
- package/es/plugins/common/thumbnail.d.ts +0 -1
- package/es/plugins/common/thumbnail.js +3 -24
- package/es/plugins/controls/index.css +132 -0
- package/es/plugins/controls/index.js +189 -0
- package/es/plugins/cssFullScreen/index.js +2 -1
- package/es/plugins/danmu/danmuIcon.js +1 -0
- package/es/plugins/danmu/danmuPanel.js +2 -2
- package/es/plugins/danmu/index.js +4 -4
- package/es/plugins/definition/index.js +2 -2
- package/es/plugins/download/index.js +3 -3
- package/es/plugins/dynamicBg/index.js +5 -5
- package/es/plugins/enter/index.js +2 -2
- package/es/plugins/error/index.js +2 -1
- package/es/plugins/fpsDetect/index.js +2 -1
- package/es/plugins/fullscreen/backicon.js +3 -3
- package/es/plugins/fullscreen/index.js +2 -2
- package/es/plugins/gapJump/index.js +2 -1
- package/es/plugins/heatmap/index.css +25 -0
- package/es/plugins/heatmap/index.d.ts +70 -0
- package/es/plugins/heatmap/index.js +306 -0
- package/es/plugins/heatmap/index.scss +28 -0
- package/es/plugins/keyboard/index.js +3 -3
- package/es/plugins/logger/index.js +11 -11
- package/es/plugins/miniScreen/index.js +6 -6
- package/es/plugins/miniScreen/miniScreenIcon.js +1 -0
- package/es/plugins/mobile/index.js +14 -14
- package/es/plugins/pc/index.js +3 -3
- package/es/plugins/pip/index.d.ts +11 -1
- package/es/plugins/pip/index.js +112 -13
- package/es/plugins/play/index.js +2 -1
- package/es/plugins/playNext/index.js +2 -1
- package/es/plugins/playbackRate/index.js +2 -1
- package/es/plugins/poster/index.css +4 -0
- package/es/plugins/poster/index.js +12 -10
- package/es/plugins/poster/index.scss +4 -0
- package/es/plugins/progress/index.js +35 -33
- package/es/plugins/progress/innerList.js +11 -9
- package/es/plugins/progress/miniProgress.js +1 -0
- package/es/plugins/progressPreview/dotsApi.js +5 -5
- package/es/plugins/progressPreview/index.d.ts +2 -2
- package/es/plugins/progressPreview/index.js +29 -29
- package/es/plugins/prompt/index.js +5 -5
- package/es/plugins/replay/index.js +3 -3
- package/es/plugins/rotate/index.js +2 -2
- package/es/plugins/screenShot/index.d.ts +1 -0
- package/es/plugins/screenShot/index.js +8 -3
- package/es/plugins/start/index.js +13 -13
- package/es/plugins/stats/index.js +1 -1
- package/es/plugins/testspeed/index.js +2 -2
- package/es/plugins/time/index.js +34 -31
- package/es/plugins/time/timesegments.js +7 -7
- package/es/plugins/track/index.js +6 -6
- package/es/plugins/volume/index.js +15 -15
- package/es/plugins/waitingTimeoutJump/index.js +2 -1
- package/es/presets/default-en.d.ts +2 -1
- package/es/presets/default-en.js +6 -4
- package/es/presets/default.d.ts +3 -2
- package/es/presets/default.js +6 -4
- package/es/stateClassMap.d.ts +1 -0
- package/es/stateClassMap.js +1 -0
- package/es/utils/database.js +107 -0
- package/es/utils/util.d.ts +300 -282
- package/es/utils/util.js +352 -145
- package/es/utils/xgplayerTimeRange.d.ts +7 -0
- package/es/utils/xgplayerTimeRange.js +25 -0
- package/es/version.js +1 -1
- package/package.json +3 -10
- package/es/simple.umd.d.ts +0 -2
- package/es/utils/throttle.d.ts +0 -12
- package/es/utils/throttle.js +0 -132
package/es/player.js
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { defineProperty as _defineProperty, inherits as _inherits, createSuper as _createSuper, createClass as _createClass, classCallCheck as _classCallCheck, assertThisInitialized as _assertThisInitialized, possibleConstructorReturn as _possibleConstructorReturn, get as _get, getPrototypeOf as _getPrototypeOf, objectSpread2 as _objectSpread2 } from "./_virtual/_rollupPluginBabelHelpers.js";
|
|
2
2
|
import MediaProxy from "./mediaProxy.js";
|
|
3
|
-
import
|
|
3
|
+
import util, { checkIsCurrentVideo } from "./utils/util.js";
|
|
4
|
+
export { default as Util } from "./utils/util.js";
|
|
4
5
|
import sniffer from "./utils/sniffer.js";
|
|
5
6
|
export { default as Sniffer } from "./utils/sniffer.js";
|
|
7
|
+
import INDEXDB from "./utils/database.js";
|
|
6
8
|
import Errors from "./error.js";
|
|
7
9
|
export { default as Errors } from "./error.js";
|
|
8
|
-
import { CANPLAY, READY, ERROR, LOADED_DATA, PLAY, URL_NULL, COMPLETE, AUTOPLAY_STARTED, AUTOPLAY_PREVENTED, SEEKED, DEFINITION_CHANGE, AFTER_DEFINITION_CHANGE, RESET, DESTROY, PLAYER_FOCUS, PLAYER_BLUR,
|
|
10
|
+
import { CANPLAY, USER_ACTION, FULLSCREEN_CHANGE, READY, ERROR, LOADED_DATA, PLAY, URL_NULL, COMPLETE, AUTOPLAY_STARTED, AUTOPLAY_PREVENTED, SEEKED, DEFINITION_CHANGE, AFTER_DEFINITION_CHANGE, RESET, DESTROY, CSS_FULLSCREEN_CHANGE, PLAYER_FOCUS, PLAYER_BLUR, VIDEO_RESIZE, REPLAY, PLAYNEXT } from "./events.js";
|
|
9
11
|
import * as events from "./events.js";
|
|
10
12
|
export { events as Events };
|
|
11
|
-
import { PLATER_ID } from "./constant.js";
|
|
13
|
+
import { PLATER_ID, FULLSCREEN_EVENTS, GET_FULLSCREEN_API, EXIT_FULLSCREEN_API } from "./constant.js";
|
|
12
14
|
import { POSITIONS } from "./plugin/plugin.js";
|
|
13
15
|
export { default as Plugin } from "./plugin/plugin.js";
|
|
14
16
|
import BasePlugin from "./plugin/basePlugin.js";
|
|
@@ -20,6 +22,8 @@ import getDefaultConfig from "./defaultConfig.js";
|
|
|
20
22
|
import { usePreset } from "./plugin/preset.js";
|
|
21
23
|
import hooksDescriptor, { runHooks, delHooksDescriptor, hook, useHooks, removeHooks, usePluginHooks, removePluginHooks } from "./plugin/hooksDescriptor.js";
|
|
22
24
|
import XG_DEBUG, { bindDebug } from "./utils/debug.js";
|
|
25
|
+
import I18N from "./lang/i18n.js";
|
|
26
|
+
export { default as I18N } from "./lang/i18n.js";
|
|
23
27
|
import version from "./version.js";
|
|
24
28
|
import { STATES, STATE_ARRAY } from "./state.js";
|
|
25
29
|
var PlAYER_HOOKS = ["play", "pause", "replay", "retry"];
|
|
@@ -31,35 +35,99 @@ var Player = /* @__PURE__ */ function(_MediaProxy) {
|
|
|
31
35
|
function Player2(options) {
|
|
32
36
|
var _this;
|
|
33
37
|
_classCallCheck(this, Player2);
|
|
34
|
-
var
|
|
35
|
-
_this = _super.call(this,
|
|
38
|
+
var _config = util.deepMerge(getDefaultConfig(), options);
|
|
39
|
+
_this = _super.call(this, _config);
|
|
36
40
|
_defineProperty(_assertThisInitialized(_this), "canPlayFunc", function() {
|
|
37
41
|
if (!_this.config) {
|
|
38
42
|
return;
|
|
39
43
|
}
|
|
40
|
-
var _this$config = _this.config, autoplay = _this$config.autoplay,
|
|
41
|
-
XG_DEBUG.logInfo("player", "canPlayFunc, startTime",
|
|
42
|
-
if (
|
|
43
|
-
_this.currentTime =
|
|
44
|
-
_this.
|
|
44
|
+
var _this$config = _this.config, autoplay = _this$config.autoplay, defaultPlaybackRate = _this$config.defaultPlaybackRate;
|
|
45
|
+
XG_DEBUG.logInfo("player", "canPlayFunc, startTime", _this.__startTime);
|
|
46
|
+
if (_this.__startTime > 0 && _this.duration > 0) {
|
|
47
|
+
_this.currentTime = _this.__startTime > _this.duration ? _this.duration : _this.__startTime;
|
|
48
|
+
_this.__startTime = -1;
|
|
45
49
|
}
|
|
46
50
|
_this.playbackRate = defaultPlaybackRate;
|
|
47
51
|
(autoplay || _this._useAutoplay) && _this.mediaPlay();
|
|
48
52
|
_this.off(CANPLAY, _this.canPlayFunc);
|
|
49
53
|
_this.removeClass(STATE_CLASS.ENTER);
|
|
50
54
|
});
|
|
55
|
+
_defineProperty(_assertThisInitialized(_this), "onFullscreenChange", function(event, isFullScreen) {
|
|
56
|
+
var delayResize = function delayResize2() {
|
|
57
|
+
util.setTimeout(_assertThisInitialized(_this), function() {
|
|
58
|
+
_this.resize();
|
|
59
|
+
}, 100);
|
|
60
|
+
};
|
|
61
|
+
var fullEl = util.getFullScreenEl();
|
|
62
|
+
if (_this._fullActionFrom) {
|
|
63
|
+
_this._fullActionFrom = "";
|
|
64
|
+
} else {
|
|
65
|
+
_this.emit(USER_ACTION, {
|
|
66
|
+
eventType: "system",
|
|
67
|
+
action: "switch_fullscreen",
|
|
68
|
+
pluginName: "player",
|
|
69
|
+
currentTime: _this.currentTime,
|
|
70
|
+
duration: _this.duration,
|
|
71
|
+
props: [{
|
|
72
|
+
prop: "fullscreen",
|
|
73
|
+
from: true,
|
|
74
|
+
to: false
|
|
75
|
+
}]
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
var isVideo = checkIsCurrentVideo(fullEl, _this.playerId, PLATER_ID);
|
|
79
|
+
if (isFullScreen || fullEl && (fullEl === _this._fullscreenEl || isVideo)) {
|
|
80
|
+
delayResize();
|
|
81
|
+
!_this.config.closeFocusVideoFocus && _this.media.focus();
|
|
82
|
+
_this.fullscreen = true;
|
|
83
|
+
_this.changeFullStyle(_this.root, fullEl, STATE_CLASS.FULLSCREEN);
|
|
84
|
+
_this.emit(FULLSCREEN_CHANGE, true, _this._fullScreenOffset);
|
|
85
|
+
if (_this.cssfullscreen) {
|
|
86
|
+
_this.exitCssFullscreen();
|
|
87
|
+
}
|
|
88
|
+
} else if (_this.fullscreen) {
|
|
89
|
+
delayResize();
|
|
90
|
+
var _assertThisInitialize = _assertThisInitialized(_this), _fullScreenOffset = _assertThisInitialize._fullScreenOffset, config = _assertThisInitialize.config;
|
|
91
|
+
if (config.needFullscreenScroll) {
|
|
92
|
+
window.scrollTo(_fullScreenOffset.left, _fullScreenOffset.top);
|
|
93
|
+
util.setTimeout(_assertThisInitialized(_this), function() {
|
|
94
|
+
_this.fullscreen = false;
|
|
95
|
+
_this._fullScreenOffset = null;
|
|
96
|
+
}, 100);
|
|
97
|
+
} else {
|
|
98
|
+
!_this.config.closeFocusVideoFocus && _this.media.focus();
|
|
99
|
+
_this.fullscreen = false;
|
|
100
|
+
_this._fullScreenOffset = null;
|
|
101
|
+
}
|
|
102
|
+
if (!_this.cssfullscreen) {
|
|
103
|
+
_this.recoverFullStyle(_this.root, _this._fullscreenEl, STATE_CLASS.FULLSCREEN);
|
|
104
|
+
} else {
|
|
105
|
+
_this.removeClass(STATE_CLASS.FULLSCREEN);
|
|
106
|
+
}
|
|
107
|
+
_this._fullscreenEl = null;
|
|
108
|
+
_this.emit(FULLSCREEN_CHANGE, false);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
_defineProperty(_assertThisInitialized(_this), "_onWebkitbeginfullscreen", function(e) {
|
|
112
|
+
_this._fullscreenEl = _this.media;
|
|
113
|
+
_this.onFullscreenChange(e, true);
|
|
114
|
+
});
|
|
115
|
+
_defineProperty(_assertThisInitialized(_this), "_onWebkitendfullscreen", function(e) {
|
|
116
|
+
_this.onFullscreenChange(e, false);
|
|
117
|
+
});
|
|
51
118
|
hooksDescriptor(_assertThisInitialized(_this), PlAYER_HOOKS);
|
|
52
|
-
_this.config =
|
|
53
|
-
_this._pluginInfoId = generateSessionId();
|
|
119
|
+
_this.config = _config;
|
|
120
|
+
_this._pluginInfoId = util.generateSessionId();
|
|
54
121
|
bindDebug(_assertThisInitialized(_this));
|
|
55
122
|
var defaultPreset = _this.constructor.defaultPreset;
|
|
56
|
-
|
|
57
|
-
|
|
123
|
+
var presets = _this.config.presets;
|
|
124
|
+
if (presets.length) {
|
|
125
|
+
var defaultIdx = presets.indexOf("default");
|
|
58
126
|
if (defaultIdx >= 0 && defaultPreset) {
|
|
59
|
-
|
|
127
|
+
presets[defaultIdx] = defaultPreset;
|
|
60
128
|
}
|
|
61
129
|
} else if (defaultPreset) {
|
|
62
|
-
|
|
130
|
+
presets.push(defaultPreset);
|
|
63
131
|
}
|
|
64
132
|
_this.userTimer = null;
|
|
65
133
|
_this.waitTimer = null;
|
|
@@ -69,6 +137,7 @@ var Player = /* @__PURE__ */ function(_MediaProxy) {
|
|
|
69
137
|
_this.isSeeking = false;
|
|
70
138
|
_this.isCanplay = false;
|
|
71
139
|
_this._useAutoplay = false;
|
|
140
|
+
_this.__startTime = -1;
|
|
72
141
|
_this.rotateDeg = 0;
|
|
73
142
|
_this.isActive = false;
|
|
74
143
|
_this.fullscreen = false;
|
|
@@ -109,20 +178,22 @@ var Player = /* @__PURE__ */ function(_MediaProxy) {
|
|
|
109
178
|
duration: 0
|
|
110
179
|
};
|
|
111
180
|
_this.innerContainer = null;
|
|
112
|
-
_this.controls = null;
|
|
113
181
|
_this.topBar = null;
|
|
114
182
|
_this.root = null;
|
|
183
|
+
_this.__i18n = I18N.init(_this._pluginInfoId);
|
|
115
184
|
if (sniffer.os.isAndroid && sniffer.osVersion > 0 && sniffer.osVersion < 6) {
|
|
116
185
|
_this.config.autoplay = false;
|
|
117
186
|
}
|
|
187
|
+
_this.database = new INDEXDB();
|
|
118
188
|
_this.isUserActive = false;
|
|
119
189
|
_this._onceSeekCanplay = null;
|
|
120
190
|
_this._isPauseBeforeSeek = 0;
|
|
121
191
|
_this.innerStates = {
|
|
122
192
|
isActiveLocked: false
|
|
123
193
|
};
|
|
124
|
-
var
|
|
125
|
-
|
|
194
|
+
var isNoRoot = _this.config.isNoRoot;
|
|
195
|
+
var rootInit = !isNoRoot && _this._initDOM();
|
|
196
|
+
if (!isNoRoot && !rootInit) {
|
|
126
197
|
console.error(new Error("can't find the dom which id is ".concat(_this.config.id, " or this.config.el does not exist")));
|
|
127
198
|
return _possibleConstructorReturn(_this);
|
|
128
199
|
}
|
|
@@ -144,7 +215,7 @@ var Player = /* @__PURE__ */ function(_MediaProxy) {
|
|
|
144
215
|
pluginsManager.onPluginsReady(_assertThisInitialized(_this));
|
|
145
216
|
_this.getInitDefinition();
|
|
146
217
|
_this.setState(STATES.READY);
|
|
147
|
-
setTimeout(_assertThisInitialized(_this), function() {
|
|
218
|
+
util.setTimeout(_assertThisInitialized(_this), function() {
|
|
148
219
|
_this.emit(READY);
|
|
149
220
|
}, 0);
|
|
150
221
|
_this.onReady && _this.onReady();
|
|
@@ -159,12 +230,12 @@ var Player = /* @__PURE__ */ function(_MediaProxy) {
|
|
|
159
230
|
key: "_initDOM",
|
|
160
231
|
value: function _initDOM() {
|
|
161
232
|
var _this2 = this;
|
|
162
|
-
|
|
233
|
+
var _this$config3 = this.config, id = _this$config3.id, el = _this$config3.el, isCustomRoot = _this$config3.isCustomRoot, controls = _this$config3.controls, autoplay = _this$config3.autoplay, isMobileSimulateMode = _this$config3.isMobileSimulateMode;
|
|
234
|
+
this.root = id ? document.getElementById(id) : null;
|
|
163
235
|
if (!this.root) {
|
|
164
|
-
var el = this.config.el;
|
|
165
236
|
if (el && el.nodeType === 1) {
|
|
166
237
|
this.root = el;
|
|
167
|
-
} else {
|
|
238
|
+
} else if (isCustomRoot) {
|
|
168
239
|
this.emit(ERROR, new Errors("use", this.config.vid, {
|
|
169
240
|
line: 32,
|
|
170
241
|
handle: "Constructor",
|
|
@@ -172,6 +243,11 @@ var Player = /* @__PURE__ */ function(_MediaProxy) {
|
|
|
172
243
|
}));
|
|
173
244
|
console.error("this.confg.id or this.config.el can't be empty");
|
|
174
245
|
return false;
|
|
246
|
+
} else {
|
|
247
|
+
this.root = util.createDom("div", "", {
|
|
248
|
+
id,
|
|
249
|
+
class: STATE_CLASS.BUILTIN_CLASS
|
|
250
|
+
});
|
|
175
251
|
}
|
|
176
252
|
}
|
|
177
253
|
var ret = pluginsManager.checkPlayerRoot(this.root);
|
|
@@ -191,15 +267,15 @@ var Player = /* @__PURE__ */ function(_MediaProxy) {
|
|
|
191
267
|
this.media = _nVideo;
|
|
192
268
|
}
|
|
193
269
|
this.media.setAttribute(PLATER_ID, this.playerId);
|
|
194
|
-
var device =
|
|
195
|
-
this.addClass("".concat(STATE_CLASS.DEFAULT, " ").concat(STATE_CLASS.INACTIVE, " xgplayer-").concat(device, " ").concat(
|
|
196
|
-
if (
|
|
270
|
+
var device = isMobileSimulateMode === "mobile" ? "mobile" : sniffer.device;
|
|
271
|
+
this.addClass("".concat(STATE_CLASS.DEFAULT, " ").concat(STATE_CLASS.INACTIVE, " xgplayer-").concat(device, " ").concat(controls ? "" : STATE_CLASS.NO_CONTROLS));
|
|
272
|
+
if (autoplay) {
|
|
197
273
|
this.addClass(STATE_CLASS.ENTER);
|
|
198
274
|
} else {
|
|
199
275
|
this.addClass(STATE_CLASS.NO_START);
|
|
200
276
|
}
|
|
201
277
|
if (this.config.fluid) {
|
|
202
|
-
var _this$
|
|
278
|
+
var _this$config4 = this.config, _width = _this$config4.width, _height = _this$config4.height;
|
|
203
279
|
if (typeof _width !== "number" || typeof _height !== "number") {
|
|
204
280
|
_width = 600;
|
|
205
281
|
_height = 337.5;
|
|
@@ -238,7 +314,7 @@ var Player = /* @__PURE__ */ function(_MediaProxy) {
|
|
|
238
314
|
this.leftBar = null;
|
|
239
315
|
this.rightBar = null;
|
|
240
316
|
if (this.config.marginControls) {
|
|
241
|
-
this.innerContainer = createDom("xg-video-container", "", {
|
|
317
|
+
this.innerContainer = util.createDom("xg-video-container", "", {
|
|
242
318
|
"data-index": -1
|
|
243
319
|
}, "xg-video-container");
|
|
244
320
|
this.root.appendChild(this.innerContainer);
|
|
@@ -251,6 +327,13 @@ var Player = /* @__PURE__ */ function(_MediaProxy) {
|
|
|
251
327
|
["focus", "blur"].forEach(function(item) {
|
|
252
328
|
_this3.on(item, _this3["on" + item.charAt(0).toUpperCase() + item.slice(1)]);
|
|
253
329
|
});
|
|
330
|
+
FULLSCREEN_EVENTS.forEach(function(item) {
|
|
331
|
+
document && document.addEventListener(item, _this3.onFullscreenChange);
|
|
332
|
+
});
|
|
333
|
+
if (sniffer.os.isIos) {
|
|
334
|
+
this.media.addEventListener("webkitbeginfullscreen", this._onWebkitbeginfullscreen);
|
|
335
|
+
this.media.addEventListener("webkitendfullscreen", this._onWebkitendfullscreen);
|
|
336
|
+
}
|
|
254
337
|
this.once(LOADED_DATA, this.resize);
|
|
255
338
|
this.playFunc = function() {
|
|
256
339
|
if (!_this3.config.closeFocusVideoFocus) {
|
|
@@ -262,18 +345,24 @@ var Player = /* @__PURE__ */ function(_MediaProxy) {
|
|
|
262
345
|
}, {
|
|
263
346
|
key: "_unbindEvents",
|
|
264
347
|
value: function _unbindEvents() {
|
|
265
|
-
|
|
348
|
+
var _this4 = this;
|
|
349
|
+
this.root && this.root.removeEventListener("mousemove", this.mousemoveFunc);
|
|
350
|
+
FULLSCREEN_EVENTS.forEach(function(item) {
|
|
351
|
+
document.removeEventListener(item, _this4.onFullscreenChange);
|
|
352
|
+
});
|
|
266
353
|
this.playFunc && this.off(PLAY, this.playFunc);
|
|
267
354
|
this.off(CANPLAY, this.canPlayFunc);
|
|
355
|
+
this.media.removeEventListener("webkitbeginfullscreen", this._onWebkitbeginfullscreen);
|
|
356
|
+
this.media.removeEventListener("webkitendfullscreen", this._onWebkitendfullscreen);
|
|
268
357
|
}
|
|
269
358
|
}, {
|
|
270
359
|
key: "_startInit",
|
|
271
360
|
value: function _startInit(url) {
|
|
272
|
-
var
|
|
361
|
+
var _this5 = this;
|
|
273
362
|
if (!this.media) {
|
|
274
363
|
return;
|
|
275
364
|
}
|
|
276
|
-
if (!url || url === "" || typeOf(url) === "Array" && url.length === 0) {
|
|
365
|
+
if (!url || url === "" || util.typeOf(url) === "Array" && url.length === 0) {
|
|
277
366
|
url = "";
|
|
278
367
|
this.emit(URL_NULL);
|
|
279
368
|
XG_DEBUG.logWarn("config.url is null, please get url and run player._startInit(url)");
|
|
@@ -282,48 +371,53 @@ var Player = /* @__PURE__ */ function(_MediaProxy) {
|
|
|
282
371
|
}
|
|
283
372
|
}
|
|
284
373
|
this._detachSourceEvents(this.media);
|
|
285
|
-
if (typeOf(url) === "Array" && url.length > 0) {
|
|
374
|
+
if (util.typeOf(url) === "Array" && url.length > 0) {
|
|
286
375
|
this._attachSourceEvents(this.media, url);
|
|
287
376
|
} else if (!this.media.src || this.media.src !== url) {
|
|
288
377
|
this.media.src = url;
|
|
289
378
|
} else if (!url) {
|
|
290
379
|
this.media.removeAttribute("src");
|
|
291
380
|
}
|
|
292
|
-
if (typeOf(this.config.volume) === "Number") {
|
|
381
|
+
if (util.typeOf(this.config.volume) === "Number") {
|
|
293
382
|
this.volume = this.config.volume;
|
|
294
383
|
}
|
|
295
384
|
var _root = this.innerContainer ? this.innerContainer : this.root;
|
|
296
|
-
if (this.media instanceof window.Element && !_root.contains(this.media)) {
|
|
385
|
+
if (_root && this.media instanceof window.Element && !_root.contains(this.media)) {
|
|
297
386
|
_root.insertBefore(this.media, _root.firstChild);
|
|
298
387
|
}
|
|
299
388
|
var readyState = this.media.readyState;
|
|
300
389
|
XG_DEBUG.logInfo("_startInit readyState", readyState);
|
|
301
390
|
if (this.config.autoplay) {
|
|
302
|
-
!isMSE(this.media) && this.load();
|
|
391
|
+
!util.isMSE(this.media) && this.load();
|
|
303
392
|
(sniffer.os.isIpad || sniffer.os.isPhone) && this.mediaPlay();
|
|
304
393
|
}
|
|
305
|
-
|
|
394
|
+
var startTime = this.config.startTime;
|
|
395
|
+
this.__startTime = startTime > 0 ? startTime : -1;
|
|
396
|
+
this.config.startTime = 0;
|
|
397
|
+
if (readyState >= 2 && this.duration > 0) {
|
|
306
398
|
this.canPlayFunc();
|
|
307
399
|
} else {
|
|
308
|
-
this.
|
|
400
|
+
this.on(CANPLAY, this.canPlayFunc);
|
|
309
401
|
}
|
|
310
402
|
if (!this.hasStart || this.state < STATES.ATTACHED) {
|
|
311
403
|
pluginsManager.afterInit(this);
|
|
312
404
|
}
|
|
313
405
|
this.hasStart = true;
|
|
314
406
|
this.setState(STATES.ATTACHED);
|
|
315
|
-
setTimeout(this, function() {
|
|
316
|
-
|
|
407
|
+
util.setTimeout(this, function() {
|
|
408
|
+
_this5.emit(COMPLETE);
|
|
317
409
|
}, 0);
|
|
318
410
|
}
|
|
319
411
|
}, {
|
|
320
412
|
key: "_registerPlugins",
|
|
321
413
|
value: function _registerPlugins() {
|
|
322
|
-
var
|
|
414
|
+
var _this6 = this;
|
|
323
415
|
var isInit = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : true;
|
|
324
416
|
this._loadingPlugins = [];
|
|
325
417
|
var ignores = this.config.ignores || [];
|
|
326
418
|
var plugins = this.config.plugins || [];
|
|
419
|
+
var i18n = this.config.i18n || [];
|
|
420
|
+
isInit && I18N.extend(i18n, this.__i18n);
|
|
327
421
|
var ignoresStr = ignores.join("||").toLowerCase().split("||");
|
|
328
422
|
var cuPlugins = this.plugins;
|
|
329
423
|
plugins.forEach(function(plugin) {
|
|
@@ -335,7 +429,20 @@ var Player = /* @__PURE__ */ function(_MediaProxy) {
|
|
|
335
429
|
if (!isInit && cuPlugins[pluginName.toLowerCase()]) {
|
|
336
430
|
return;
|
|
337
431
|
}
|
|
338
|
-
|
|
432
|
+
if (plugin.lazy && plugin.loader) {
|
|
433
|
+
var loadingPlugin = pluginsManager.lazyRegister(_this6, plugin);
|
|
434
|
+
if (plugin.forceBeforeInit) {
|
|
435
|
+
loadingPlugin.then(function() {
|
|
436
|
+
_this6._loadingPlugins.splice(_this6._loadingPlugins.indexOf(loadingPlugin), 1);
|
|
437
|
+
}).catch(function(e) {
|
|
438
|
+
XG_DEBUG.logError("_registerPlugins:loadingPlugin", e);
|
|
439
|
+
_this6._loadingPlugins.splice(_this6._loadingPlugins.indexOf(loadingPlugin), 1);
|
|
440
|
+
});
|
|
441
|
+
_this6._loadingPlugins.push(loadingPlugin);
|
|
442
|
+
}
|
|
443
|
+
return;
|
|
444
|
+
}
|
|
445
|
+
return _this6.registerPlugin(plugin);
|
|
339
446
|
} catch (err) {
|
|
340
447
|
XG_DEBUG.logError("_registerPlugins:", err);
|
|
341
448
|
}
|
|
@@ -344,9 +451,9 @@ var Player = /* @__PURE__ */ function(_MediaProxy) {
|
|
|
344
451
|
}, {
|
|
345
452
|
key: "_registerPresets",
|
|
346
453
|
value: function _registerPresets() {
|
|
347
|
-
var
|
|
454
|
+
var _this7 = this;
|
|
348
455
|
this.config.presets.forEach(function(preset) {
|
|
349
|
-
usePreset(
|
|
456
|
+
usePreset(_this7, preset);
|
|
350
457
|
});
|
|
351
458
|
}
|
|
352
459
|
}, {
|
|
@@ -356,21 +463,21 @@ var Player = /* @__PURE__ */ function(_MediaProxy) {
|
|
|
356
463
|
switch (position) {
|
|
357
464
|
case POSITIONS.ROOT_RIGHT:
|
|
358
465
|
if (!this.rightBar) {
|
|
359
|
-
this.rightBar = createPositionBar("xg-right-bar", this.root);
|
|
466
|
+
this.rightBar = util.createPositionBar("xg-right-bar", this.root);
|
|
360
467
|
}
|
|
361
468
|
_root = this.rightBar;
|
|
362
469
|
break;
|
|
363
470
|
case POSITIONS.ROOT_LEFT:
|
|
364
471
|
if (!this.leftBar) {
|
|
365
|
-
this.leftBar = createPositionBar("xg-left-bar", this.root);
|
|
472
|
+
this.leftBar = util.createPositionBar("xg-left-bar", this.root);
|
|
366
473
|
}
|
|
367
474
|
_root = this.leftBar;
|
|
368
475
|
break;
|
|
369
476
|
case POSITIONS.ROOT_TOP:
|
|
370
477
|
if (!this.topBar) {
|
|
371
|
-
this.topBar = createPositionBar("xg-top-bar", this.root);
|
|
478
|
+
this.topBar = util.createPositionBar("xg-top-bar", this.root);
|
|
372
479
|
if (this.config.topBarAutoHide) {
|
|
373
|
-
addClass(this.topBar, STATE_CLASS.TOP_BAR_AUTOHIDE);
|
|
480
|
+
util.addClass(this.topBar, STATE_CLASS.TOP_BAR_AUTOHIDE);
|
|
374
481
|
}
|
|
375
482
|
}
|
|
376
483
|
_root = this.topBar;
|
|
@@ -397,26 +504,27 @@ var Player = /* @__PURE__ */ function(_MediaProxy) {
|
|
|
397
504
|
return this.controls && this.controls.registerPlugin(PLUFGIN, options, PLUFGIN.pluginName);
|
|
398
505
|
}
|
|
399
506
|
if (!options.root) {
|
|
400
|
-
options.root = this._getRootByPosition(position);
|
|
507
|
+
options.root = PLUFGIN.pluginName === "controls" ? this.root : this._getRootByPosition(position);
|
|
401
508
|
}
|
|
402
509
|
return pluginsManager.register(this, PLUFGIN, options);
|
|
403
510
|
}
|
|
404
511
|
}, {
|
|
405
512
|
key: "deregister",
|
|
406
|
-
value: function deregister(plugin
|
|
513
|
+
value: function deregister(plugin) {
|
|
407
514
|
if (typeof plugin === "string") {
|
|
408
515
|
pluginsManager.unRegister(this, plugin);
|
|
409
516
|
} else if (plugin instanceof BasePlugin) {
|
|
410
517
|
pluginsManager.unRegister(this, plugin.pluginName);
|
|
411
518
|
}
|
|
412
|
-
if (removedFromConfig) {
|
|
413
|
-
this.removePluginFromConfig(plugin);
|
|
414
|
-
}
|
|
415
519
|
}
|
|
416
520
|
}, {
|
|
417
521
|
key: "unRegisterPlugin",
|
|
418
522
|
value: function unRegisterPlugin(plugin) {
|
|
523
|
+
var removedFromConfig = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
|
|
419
524
|
this.deregister(plugin);
|
|
525
|
+
if (removedFromConfig) {
|
|
526
|
+
this.removePluginFromConfig(plugin);
|
|
527
|
+
}
|
|
420
528
|
}
|
|
421
529
|
}, {
|
|
422
530
|
key: "removePluginFromConfig",
|
|
@@ -451,29 +559,29 @@ var Player = /* @__PURE__ */ function(_MediaProxy) {
|
|
|
451
559
|
}
|
|
452
560
|
}, {
|
|
453
561
|
key: "addClass",
|
|
454
|
-
value: function addClass
|
|
562
|
+
value: function addClass(className) {
|
|
455
563
|
if (!this.root) {
|
|
456
564
|
return;
|
|
457
565
|
}
|
|
458
|
-
if (!hasClass(this.root, className)) {
|
|
459
|
-
addClass(this.root, className);
|
|
566
|
+
if (!util.hasClass(this.root, className)) {
|
|
567
|
+
util.addClass(this.root, className);
|
|
460
568
|
}
|
|
461
569
|
}
|
|
462
570
|
}, {
|
|
463
571
|
key: "removeClass",
|
|
464
|
-
value: function removeClass
|
|
572
|
+
value: function removeClass(className) {
|
|
465
573
|
if (!this.root) {
|
|
466
574
|
return;
|
|
467
575
|
}
|
|
468
|
-
removeClass(this.root, className);
|
|
576
|
+
util.removeClass(this.root, className);
|
|
469
577
|
}
|
|
470
578
|
}, {
|
|
471
579
|
key: "hasClass",
|
|
472
|
-
value: function hasClass
|
|
580
|
+
value: function hasClass(className) {
|
|
473
581
|
if (!this.root) {
|
|
474
582
|
return;
|
|
475
583
|
}
|
|
476
|
-
return hasClass(this.root, className);
|
|
584
|
+
return util.hasClass(this.root, className);
|
|
477
585
|
}
|
|
478
586
|
}, {
|
|
479
587
|
key: "setAttribute",
|
|
@@ -494,7 +602,7 @@ var Player = /* @__PURE__ */ function(_MediaProxy) {
|
|
|
494
602
|
}, {
|
|
495
603
|
key: "start",
|
|
496
604
|
value: function start(url) {
|
|
497
|
-
var
|
|
605
|
+
var _this8 = this;
|
|
498
606
|
if (this.state > STATES.ATTACHING) {
|
|
499
607
|
return;
|
|
500
608
|
}
|
|
@@ -505,14 +613,14 @@ var Player = /* @__PURE__ */ function(_MediaProxy) {
|
|
|
505
613
|
this.setState(STATES.ATTACHING);
|
|
506
614
|
this._registerPlugins(false);
|
|
507
615
|
return pluginsManager.beforeInit(this).then(function() {
|
|
508
|
-
if (!
|
|
616
|
+
if (!_this8.config) {
|
|
509
617
|
return;
|
|
510
618
|
}
|
|
511
619
|
if (!url) {
|
|
512
|
-
url =
|
|
620
|
+
url = _this8.url || _this8.config.url;
|
|
513
621
|
}
|
|
514
|
-
var _furl =
|
|
515
|
-
var ret =
|
|
622
|
+
var _furl = _this8.preProcessUrl(url);
|
|
623
|
+
var ret = _this8._startInit(_furl.url);
|
|
516
624
|
return ret;
|
|
517
625
|
}).catch(function(e) {
|
|
518
626
|
e.fileName = "player";
|
|
@@ -524,43 +632,47 @@ var Player = /* @__PURE__ */ function(_MediaProxy) {
|
|
|
524
632
|
}, {
|
|
525
633
|
key: "switchURL",
|
|
526
634
|
value: function switchURL(url, options) {
|
|
527
|
-
var
|
|
635
|
+
var _this9 = this;
|
|
528
636
|
var _src = url;
|
|
529
|
-
if (typeOf(url) === "Object") {
|
|
637
|
+
if (util.typeOf(url) === "Object") {
|
|
530
638
|
_src = url.url;
|
|
531
639
|
}
|
|
532
640
|
_src = this.preProcessUrl(_src).url;
|
|
533
641
|
var curTime = this.currentTime;
|
|
642
|
+
this.__startTime = curTime;
|
|
534
643
|
var isPaused = this.paused && !this.isError;
|
|
535
644
|
this.src = _src;
|
|
536
645
|
return new Promise(function(resolve, reject) {
|
|
537
646
|
var _error = function _error2(e) {
|
|
538
|
-
|
|
539
|
-
|
|
647
|
+
_this9.off("timeupdate", _canplay);
|
|
648
|
+
_this9.off("canplay", _canplay);
|
|
540
649
|
reject(e);
|
|
541
650
|
};
|
|
542
651
|
var _canplay = function _canplay2() {
|
|
543
|
-
|
|
652
|
+
if (_this9.duration > 0 && _this9.__startTime > 0) {
|
|
653
|
+
_this9.currentTime = _this9.__startTime;
|
|
654
|
+
_this9.__startTime = -1;
|
|
655
|
+
}
|
|
544
656
|
if (isPaused) {
|
|
545
|
-
|
|
657
|
+
_this9.pause();
|
|
546
658
|
}
|
|
547
|
-
|
|
659
|
+
_this9.off("error", _error);
|
|
548
660
|
resolve(true);
|
|
549
661
|
};
|
|
550
|
-
|
|
662
|
+
_this9.once("error", _error);
|
|
551
663
|
if (!_src) {
|
|
552
|
-
|
|
664
|
+
_this9.errorHandler("error", {
|
|
553
665
|
code: 6,
|
|
554
666
|
message: "empty_src"
|
|
555
667
|
});
|
|
556
668
|
return;
|
|
557
669
|
}
|
|
558
670
|
if (sniffer.os.isAndroid) {
|
|
559
|
-
|
|
671
|
+
_this9.once("timeupdate", _canplay);
|
|
560
672
|
} else {
|
|
561
|
-
|
|
673
|
+
_this9.once("canplay", _canplay);
|
|
562
674
|
}
|
|
563
|
-
|
|
675
|
+
_this9.play();
|
|
564
676
|
});
|
|
565
677
|
}
|
|
566
678
|
}, {
|
|
@@ -571,7 +683,7 @@ var Player = /* @__PURE__ */ function(_MediaProxy) {
|
|
|
571
683
|
}, {
|
|
572
684
|
key: "mediaPlay",
|
|
573
685
|
value: function mediaPlay() {
|
|
574
|
-
var
|
|
686
|
+
var _this10 = this;
|
|
575
687
|
if (!this.hasStart && this.state < STATES.ATTACHED) {
|
|
576
688
|
this.removeClass(STATE_CLASS.NO_START);
|
|
577
689
|
this.addClass(STATE_CLASS.ENTER);
|
|
@@ -586,28 +698,28 @@ var Player = /* @__PURE__ */ function(_MediaProxy) {
|
|
|
586
698
|
var playPromise = _get(_getPrototypeOf(Player2.prototype), "play", this).call(this);
|
|
587
699
|
if (playPromise !== void 0 && playPromise && playPromise.then) {
|
|
588
700
|
playPromise.then(function() {
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
if (
|
|
701
|
+
_this10.removeClass(STATE_CLASS.NOT_ALLOW_AUTOPLAY);
|
|
702
|
+
_this10.addClass(STATE_CLASS.PLAYING);
|
|
703
|
+
if (_this10.state < STATES.RUNNING) {
|
|
592
704
|
XG_DEBUG.logInfo(">>>>playPromise.then");
|
|
593
|
-
|
|
594
|
-
|
|
705
|
+
_this10.setState(STATES.RUNNING);
|
|
706
|
+
_this10.emit(AUTOPLAY_STARTED);
|
|
595
707
|
}
|
|
596
708
|
}).catch(function(e) {
|
|
597
709
|
XG_DEBUG.logWarn(">>>>playPromise.catch", e.name);
|
|
598
|
-
if (
|
|
599
|
-
|
|
600
|
-
|
|
710
|
+
if (_this10.media && _this10.media.error) {
|
|
711
|
+
_this10.onError();
|
|
712
|
+
_this10.removeClass(STATE_CLASS.ENTER);
|
|
601
713
|
return;
|
|
602
714
|
}
|
|
603
715
|
if (e.name === "NotAllowedError") {
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
716
|
+
_this10._errorTimer = util.setTimeout(_this10, function() {
|
|
717
|
+
_this10._errorTimer = null;
|
|
718
|
+
_this10.emit(AUTOPLAY_PREVENTED);
|
|
719
|
+
_this10.addClass(STATE_CLASS.NOT_ALLOW_AUTOPLAY);
|
|
720
|
+
_this10.removeClass(STATE_CLASS.ENTER);
|
|
721
|
+
_this10.pause();
|
|
722
|
+
_this10.setState(STATES.NOTALLOW);
|
|
611
723
|
}, 0);
|
|
612
724
|
}
|
|
613
725
|
});
|
|
@@ -637,47 +749,47 @@ var Player = /* @__PURE__ */ function(_MediaProxy) {
|
|
|
637
749
|
}, {
|
|
638
750
|
key: "play",
|
|
639
751
|
value: function play() {
|
|
640
|
-
var
|
|
752
|
+
var _this11 = this;
|
|
641
753
|
this.removeClass(STATE_CLASS.PAUSED);
|
|
642
754
|
return runHooks(this, "play", function() {
|
|
643
|
-
return
|
|
755
|
+
return _this11.mediaPlay();
|
|
644
756
|
});
|
|
645
757
|
}
|
|
646
758
|
}, {
|
|
647
759
|
key: "pause",
|
|
648
760
|
value: function pause() {
|
|
649
|
-
var
|
|
761
|
+
var _this12 = this;
|
|
650
762
|
runHooks(this, "pause", function() {
|
|
651
|
-
_get(_getPrototypeOf(Player2.prototype), "pause",
|
|
763
|
+
_get(_getPrototypeOf(Player2.prototype), "pause", _this12).call(_this12);
|
|
652
764
|
});
|
|
653
765
|
}
|
|
654
766
|
}, {
|
|
655
767
|
key: "seek",
|
|
656
768
|
value: function seek(time, status) {
|
|
657
|
-
var
|
|
769
|
+
var _this13 = this;
|
|
658
770
|
if (!this.media || Number.isNaN(Number(time)) || !this.hasStart) {
|
|
659
771
|
return;
|
|
660
772
|
}
|
|
661
|
-
var _this$
|
|
773
|
+
var _this$config5 = this.config, isSeekedPlay = _this$config5.isSeekedPlay, seekedStatus = _this$config5.seekedStatus;
|
|
662
774
|
var _status = status || (isSeekedPlay ? "play" : seekedStatus);
|
|
663
775
|
time = time < 0 ? 0 : time > this.duration ? parseInt(this.duration, 10) : time;
|
|
664
776
|
!this._isPauseBeforeSeek && (this._isPauseBeforeSeek = this.paused ? 2 : 1);
|
|
665
777
|
this._onceSeekCanplay && this.off(SEEKED, this._onceSeekCanplay);
|
|
666
778
|
this._onceSeekCanplay = function() {
|
|
667
|
-
|
|
668
|
-
|
|
779
|
+
_this13.removeClass(STATE_CLASS.ENTER);
|
|
780
|
+
_this13.isSeeking = false;
|
|
669
781
|
switch (_status) {
|
|
670
782
|
case "play":
|
|
671
|
-
|
|
783
|
+
_this13.play();
|
|
672
784
|
break;
|
|
673
785
|
case "pause":
|
|
674
|
-
|
|
786
|
+
_this13.pause();
|
|
675
787
|
break;
|
|
676
788
|
default:
|
|
677
|
-
|
|
789
|
+
_this13._isPauseBeforeSeek > 1 || _this13.paused ? _this13.pause() : _this13.play();
|
|
678
790
|
}
|
|
679
|
-
|
|
680
|
-
|
|
791
|
+
_this13._isPauseBeforeSeek = 0;
|
|
792
|
+
_this13._onceSeekCanplay = null;
|
|
681
793
|
};
|
|
682
794
|
this.once(SEEKED, this._onceSeekCanplay);
|
|
683
795
|
if (this.state < STATES.RUNNING) {
|
|
@@ -691,13 +803,13 @@ var Player = /* @__PURE__ */ function(_MediaProxy) {
|
|
|
691
803
|
}, {
|
|
692
804
|
key: "getInitDefinition",
|
|
693
805
|
value: function getInitDefinition() {
|
|
694
|
-
var
|
|
695
|
-
var _this$
|
|
806
|
+
var _this14 = this;
|
|
807
|
+
var _this$config6 = this.config, definition = _this$config6.definition, url = _this$config6.url;
|
|
696
808
|
if (!url && definition && definition.list && definition.list.length > 0 && definition.defaultDefinition) {
|
|
697
809
|
definition.list.map(function(item) {
|
|
698
810
|
if (item.definition === definition.defaultDefinition) {
|
|
699
|
-
|
|
700
|
-
|
|
811
|
+
_this14.config.url = item.url;
|
|
812
|
+
_this14.curDefinition = item;
|
|
701
813
|
}
|
|
702
814
|
});
|
|
703
815
|
}
|
|
@@ -705,12 +817,12 @@ var Player = /* @__PURE__ */ function(_MediaProxy) {
|
|
|
705
817
|
}, {
|
|
706
818
|
key: "changeDefinition",
|
|
707
819
|
value: function changeDefinition(to, from) {
|
|
708
|
-
var
|
|
820
|
+
var _this15 = this;
|
|
709
821
|
var definition = this.config.definition;
|
|
710
822
|
if (Array.isArray(definition === null || definition === void 0 ? void 0 : definition.list)) {
|
|
711
823
|
definition.list.forEach(function(item) {
|
|
712
824
|
if ((to === null || to === void 0 ? void 0 : to.definition) === item.definition) {
|
|
713
|
-
|
|
825
|
+
_this15.curDefinition = item;
|
|
714
826
|
}
|
|
715
827
|
});
|
|
716
828
|
}
|
|
@@ -730,7 +842,7 @@ var Player = /* @__PURE__ */ function(_MediaProxy) {
|
|
|
730
842
|
}, to));
|
|
731
843
|
if (ret && ret.then) {
|
|
732
844
|
ret.then(function() {
|
|
733
|
-
|
|
845
|
+
_this15.emit(AFTER_DEFINITION_CHANGE, {
|
|
734
846
|
from,
|
|
735
847
|
to
|
|
736
848
|
});
|
|
@@ -754,7 +866,7 @@ var Player = /* @__PURE__ */ function(_MediaProxy) {
|
|
|
754
866
|
}, {
|
|
755
867
|
key: "resetState",
|
|
756
868
|
value: function resetState() {
|
|
757
|
-
var
|
|
869
|
+
var _this16 = this;
|
|
758
870
|
var NOT_ALLOW_AUTOPLAY = STATE_CLASS.NOT_ALLOW_AUTOPLAY, PLAYING = STATE_CLASS.PLAYING, NO_START = STATE_CLASS.NO_START, PAUSED = STATE_CLASS.PAUSED, REPLAY2 = STATE_CLASS.REPLAY, ENTER = STATE_CLASS.ENTER, ENDED = STATE_CLASS.ENDED, ERROR2 = STATE_CLASS.ERROR, LOADING = STATE_CLASS.LOADING;
|
|
759
871
|
var clsList = [NOT_ALLOW_AUTOPLAY, PLAYING, NO_START, PAUSED, REPLAY2, ENTER, ENDED, ERROR2, LOADING];
|
|
760
872
|
this.hasStart = false;
|
|
@@ -765,15 +877,15 @@ var Player = /* @__PURE__ */ function(_MediaProxy) {
|
|
|
765
877
|
this._accPlayed.t = 0;
|
|
766
878
|
this._accPlayed.loopAcc = 0;
|
|
767
879
|
clsList.forEach(function(cls) {
|
|
768
|
-
|
|
880
|
+
_this16.removeClass(cls);
|
|
769
881
|
});
|
|
770
|
-
this.addClass(STATE_CLASS.
|
|
882
|
+
this.addClass(STATE_CLASS.NO_START);
|
|
771
883
|
this.emit(RESET);
|
|
772
884
|
}
|
|
773
885
|
}, {
|
|
774
886
|
key: "reset",
|
|
775
887
|
value: function reset() {
|
|
776
|
-
var
|
|
888
|
+
var _this17 = this;
|
|
777
889
|
var unregisterPlugins = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [];
|
|
778
890
|
var isResetConfig = arguments.length > 1 ? arguments[1] : void 0;
|
|
779
891
|
this.resetState();
|
|
@@ -782,13 +894,13 @@ var Player = /* @__PURE__ */ function(_MediaProxy) {
|
|
|
782
894
|
return;
|
|
783
895
|
}
|
|
784
896
|
unregisterPlugins.map(function(pn) {
|
|
785
|
-
|
|
897
|
+
_this17.deregister(pn);
|
|
786
898
|
});
|
|
787
899
|
if (isResetConfig) {
|
|
788
900
|
var de = getDefaultConfig();
|
|
789
901
|
Object.keys(this.config).keys(function(k) {
|
|
790
|
-
if (
|
|
791
|
-
|
|
902
|
+
if (_this17.config[k] !== "undefined" && (k === "plugins" || k === "presets" || k === "el" || k === "id")) {
|
|
903
|
+
_this17.config[k] = de[k];
|
|
792
904
|
}
|
|
793
905
|
});
|
|
794
906
|
}
|
|
@@ -796,7 +908,7 @@ var Player = /* @__PURE__ */ function(_MediaProxy) {
|
|
|
796
908
|
}, {
|
|
797
909
|
key: "destroy",
|
|
798
910
|
value: function destroy() {
|
|
799
|
-
var
|
|
911
|
+
var _this18 = this;
|
|
800
912
|
var innerContainer = this.innerContainer, root = this.root, media = this.media;
|
|
801
913
|
if (!root || !media) {
|
|
802
914
|
return;
|
|
@@ -807,7 +919,7 @@ var Player = /* @__PURE__ */ function(_MediaProxy) {
|
|
|
807
919
|
this.updateAcc("destroy");
|
|
808
920
|
this._unbindEvents();
|
|
809
921
|
this._detachSourceEvents(this.media);
|
|
810
|
-
clearAllTimers(this);
|
|
922
|
+
util.clearAllTimers(this);
|
|
811
923
|
this.emit(DESTROY);
|
|
812
924
|
pluginsManager.destroy(this);
|
|
813
925
|
delHooksDescriptor(this);
|
|
@@ -823,10 +935,11 @@ var Player = /* @__PURE__ */ function(_MediaProxy) {
|
|
|
823
935
|
}
|
|
824
936
|
!innerContainer && media instanceof window.Node && root.contains(media) && root.removeChild(media);
|
|
825
937
|
["topBar", "leftBar", "rightBar", "innerContainer"].map(function(item) {
|
|
826
|
-
|
|
827
|
-
|
|
938
|
+
_this18[item] && root.removeChild(_this18[item]);
|
|
939
|
+
_this18[item] = null;
|
|
828
940
|
});
|
|
829
941
|
var cList = root.className.split(" ");
|
|
942
|
+
var isBuildIn = util.hasClass(this.root, STATE_CLASS.BUILTIN_CLASS);
|
|
830
943
|
if (cList.length > 0) {
|
|
831
944
|
root.className = cList.filter(function(name) {
|
|
832
945
|
return name.indexOf("xgplayer") < 0;
|
|
@@ -836,49 +949,242 @@ var Player = /* @__PURE__ */ function(_MediaProxy) {
|
|
|
836
949
|
}
|
|
837
950
|
this.removeAttribute("data-xgfill");
|
|
838
951
|
["isSeeking", "isCanplay", "isActive", "cssfullscreen", "fullscreen"].forEach(function(key) {
|
|
839
|
-
|
|
952
|
+
_this18[key] = false;
|
|
840
953
|
});
|
|
954
|
+
isBuildIn && this.root.parentNode && this.root.parentNode.removeChild(this.root);
|
|
841
955
|
}
|
|
842
956
|
}, {
|
|
843
957
|
key: "replay",
|
|
844
958
|
value: function replay() {
|
|
845
|
-
var
|
|
959
|
+
var _this19 = this;
|
|
846
960
|
this.removeClass(STATE_CLASS.ENDED);
|
|
847
961
|
this.currentTime = 0;
|
|
848
962
|
this.isSeeking = false;
|
|
849
963
|
runHooks(this, "replay", function() {
|
|
850
|
-
|
|
851
|
-
var playPromise =
|
|
964
|
+
_this19.once(SEEKED, function() {
|
|
965
|
+
var playPromise = _this19.mediaPlay();
|
|
852
966
|
if (playPromise && playPromise.catch) {
|
|
853
967
|
playPromise.catch(function(err) {
|
|
854
968
|
console.log(err);
|
|
855
969
|
});
|
|
856
970
|
}
|
|
857
971
|
});
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
972
|
+
_this19.play();
|
|
973
|
+
_this19.emit(REPLAY);
|
|
974
|
+
_this19.onPlay();
|
|
861
975
|
});
|
|
862
976
|
}
|
|
863
977
|
}, {
|
|
864
978
|
key: "retry",
|
|
865
979
|
value: function retry() {
|
|
866
|
-
var
|
|
980
|
+
var _this20 = this;
|
|
867
981
|
this.removeClass(STATE_CLASS.ERROR);
|
|
868
982
|
this.addClass(STATE_CLASS.LOADING);
|
|
869
983
|
runHooks(this, "retry", function() {
|
|
870
|
-
var cur =
|
|
871
|
-
var url =
|
|
872
|
-
var _srcRet = !isMSE(
|
|
984
|
+
var cur = _this20.currentTime;
|
|
985
|
+
var url = _this20.config.url;
|
|
986
|
+
var _srcRet = !util.isMSE(_this20.media) ? _this20.preProcessUrl(url) : {
|
|
873
987
|
url
|
|
874
988
|
};
|
|
875
|
-
|
|
876
|
-
!
|
|
877
|
-
|
|
878
|
-
|
|
989
|
+
_this20.src = _srcRet.url;
|
|
990
|
+
!_this20.config.isLive && (_this20.currentTime = cur);
|
|
991
|
+
_this20.once(CANPLAY, function() {
|
|
992
|
+
_this20.mediaPlay();
|
|
879
993
|
});
|
|
880
994
|
});
|
|
881
995
|
}
|
|
996
|
+
}, {
|
|
997
|
+
key: "changeFullStyle",
|
|
998
|
+
value: function changeFullStyle(root, el, rootClass, pClassName) {
|
|
999
|
+
if (!root) {
|
|
1000
|
+
return;
|
|
1001
|
+
}
|
|
1002
|
+
if (!pClassName) {
|
|
1003
|
+
pClassName = STATE_CLASS.PARENT_FULLSCREEN;
|
|
1004
|
+
}
|
|
1005
|
+
if (!this._orgCss) {
|
|
1006
|
+
this._orgCss = util.filterStyleFromText(root);
|
|
1007
|
+
}
|
|
1008
|
+
util.addClass(root, rootClass);
|
|
1009
|
+
if (el && el !== root && !this._orgPCss) {
|
|
1010
|
+
this._orgPCss = util.filterStyleFromText(el);
|
|
1011
|
+
util.addClass(el, pClassName);
|
|
1012
|
+
el.setAttribute(PLATER_ID, this.playerId);
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
1015
|
+
}, {
|
|
1016
|
+
key: "recoverFullStyle",
|
|
1017
|
+
value: function recoverFullStyle(root, el, rootClass, pClassName) {
|
|
1018
|
+
if (!pClassName) {
|
|
1019
|
+
pClassName = STATE_CLASS.PARENT_FULLSCREEN;
|
|
1020
|
+
}
|
|
1021
|
+
if (this._orgCss) {
|
|
1022
|
+
util.setStyleFromCsstext(root, this._orgCss);
|
|
1023
|
+
this._orgCss = "";
|
|
1024
|
+
}
|
|
1025
|
+
util.removeClass(root, rootClass);
|
|
1026
|
+
if (el && el !== root && this._orgPCss) {
|
|
1027
|
+
util.setStyleFromCsstext(el, this._orgPCss);
|
|
1028
|
+
this._orgPCss = "";
|
|
1029
|
+
util.removeClass(el, pClassName);
|
|
1030
|
+
el.removeAttribute(PLATER_ID);
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
}, {
|
|
1034
|
+
key: "getFullscreen",
|
|
1035
|
+
value: function getFullscreen() {
|
|
1036
|
+
var el = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : this.config.fullscreenTarget;
|
|
1037
|
+
var root = this.root, media = this.media;
|
|
1038
|
+
if (!el) {
|
|
1039
|
+
el = root;
|
|
1040
|
+
}
|
|
1041
|
+
this._fullScreenOffset = {
|
|
1042
|
+
top: util.scrollTop(),
|
|
1043
|
+
left: util.scrollLeft()
|
|
1044
|
+
};
|
|
1045
|
+
this._fullscreenEl = el;
|
|
1046
|
+
this._fullActionFrom = "get";
|
|
1047
|
+
var fullEl = util.getFullScreenEl();
|
|
1048
|
+
if (fullEl === this._fullscreenEl) {
|
|
1049
|
+
this.onFullscreenChange();
|
|
1050
|
+
return Promise.resolve();
|
|
1051
|
+
}
|
|
1052
|
+
try {
|
|
1053
|
+
for (var i = 0; i < GET_FULLSCREEN_API.length; i++) {
|
|
1054
|
+
var key = GET_FULLSCREEN_API[i];
|
|
1055
|
+
if (el[key]) {
|
|
1056
|
+
var ret = key === "webkitRequestFullscreen" ? el.webkitRequestFullscreen(window.Element.ALLOW_KEYBOARD_INPUT) : el[key]();
|
|
1057
|
+
if (ret && ret.then) {
|
|
1058
|
+
return ret;
|
|
1059
|
+
} else {
|
|
1060
|
+
return Promise.resolve();
|
|
1061
|
+
}
|
|
1062
|
+
}
|
|
1063
|
+
}
|
|
1064
|
+
if (media.fullscreenEnabled || media.webkitSupportsFullscreen) {
|
|
1065
|
+
media.webkitEnterFullscreen();
|
|
1066
|
+
return Promise.resolve();
|
|
1067
|
+
}
|
|
1068
|
+
return Promise.reject(new Error("call getFullscreen fail"));
|
|
1069
|
+
} catch (err) {
|
|
1070
|
+
return Promise.reject(new Error("call getFullscreen fail"));
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
1073
|
+
}, {
|
|
1074
|
+
key: "exitFullscreen",
|
|
1075
|
+
value: function exitFullscreen(el) {
|
|
1076
|
+
if (this.isRotateFullscreen) {
|
|
1077
|
+
this.exitRotateFullscreen();
|
|
1078
|
+
}
|
|
1079
|
+
if (!this._fullscreenEl && !util.getFullScreenEl()) {
|
|
1080
|
+
return;
|
|
1081
|
+
}
|
|
1082
|
+
this.root;
|
|
1083
|
+
var media = this.media;
|
|
1084
|
+
this._fullActionFrom = "exit";
|
|
1085
|
+
try {
|
|
1086
|
+
for (var i = 0; i < EXIT_FULLSCREEN_API.length; i++) {
|
|
1087
|
+
var key = EXIT_FULLSCREEN_API[i];
|
|
1088
|
+
if (document[key]) {
|
|
1089
|
+
var ret = document[key]();
|
|
1090
|
+
if (ret && ret.then) {
|
|
1091
|
+
return ret;
|
|
1092
|
+
} else {
|
|
1093
|
+
return Promise.resolve();
|
|
1094
|
+
}
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
1097
|
+
if (media && media.webkitSupportsFullscreen) {
|
|
1098
|
+
media.webkitExitFullScreen();
|
|
1099
|
+
return Promise.resolve();
|
|
1100
|
+
}
|
|
1101
|
+
return Promise.reject(new Error("call exitFullscreen fail"));
|
|
1102
|
+
} catch (err) {
|
|
1103
|
+
return Promise.reject(new Error("call exitFullscreen fail"));
|
|
1104
|
+
}
|
|
1105
|
+
}
|
|
1106
|
+
}, {
|
|
1107
|
+
key: "getCssFullscreen",
|
|
1108
|
+
value: function getCssFullscreen() {
|
|
1109
|
+
var el = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : this.config.fullscreenTarget;
|
|
1110
|
+
if (this.isRotateFullscreen) {
|
|
1111
|
+
this.exitRotateFullscreen();
|
|
1112
|
+
} else if (this.fullscreen) {
|
|
1113
|
+
this.exitFullscreen();
|
|
1114
|
+
}
|
|
1115
|
+
var _class = el ? "".concat(STATE_CLASS.INNER_FULLSCREEN, " ").concat(STATE_CLASS.CSS_FULLSCREEN) : STATE_CLASS.CSS_FULLSCREEN;
|
|
1116
|
+
this.changeFullStyle(this.root, el, _class);
|
|
1117
|
+
var _this$config$fullscre = this.config.fullscreen, fullscreen = _this$config$fullscre === void 0 ? {} : _this$config$fullscre;
|
|
1118
|
+
var useCssFullscreen = fullscreen.useCssFullscreen === true || typeof fullscreen.useCssFullscreen === "function" && fullscreen.useCssFullscreen();
|
|
1119
|
+
if (useCssFullscreen) {
|
|
1120
|
+
this.fullscreen = true;
|
|
1121
|
+
this.emit(FULLSCREEN_CHANGE, true);
|
|
1122
|
+
}
|
|
1123
|
+
this._cssfullscreenEl = el;
|
|
1124
|
+
this.cssfullscreen = true;
|
|
1125
|
+
this.emit(CSS_FULLSCREEN_CHANGE, true);
|
|
1126
|
+
}
|
|
1127
|
+
}, {
|
|
1128
|
+
key: "exitCssFullscreen",
|
|
1129
|
+
value: function exitCssFullscreen() {
|
|
1130
|
+
var _class = this._cssfullscreenEl ? "".concat(STATE_CLASS.INNER_FULLSCREEN, " ").concat(STATE_CLASS.CSS_FULLSCREEN) : STATE_CLASS.CSS_FULLSCREEN;
|
|
1131
|
+
if (!this.fullscreen) {
|
|
1132
|
+
this.recoverFullStyle(this.root, this._cssfullscreenEl, _class);
|
|
1133
|
+
} else {
|
|
1134
|
+
var _this$config$fullscre2 = this.config.fullscreen, fullscreen = _this$config$fullscre2 === void 0 ? {} : _this$config$fullscre2;
|
|
1135
|
+
var useCssFullscreen = fullscreen.useCssFullscreen === true || typeof fullscreen.useCssFullscreen === "function" && fullscreen.useCssFullscreen();
|
|
1136
|
+
if (useCssFullscreen) {
|
|
1137
|
+
this.recoverFullStyle(this.root, this._cssfullscreenEl, _class);
|
|
1138
|
+
this.fullscreen = false;
|
|
1139
|
+
this.emit(FULLSCREEN_CHANGE, false);
|
|
1140
|
+
} else {
|
|
1141
|
+
this.removeClass(_class);
|
|
1142
|
+
}
|
|
1143
|
+
}
|
|
1144
|
+
this._cssfullscreenEl = null;
|
|
1145
|
+
this.cssfullscreen = false;
|
|
1146
|
+
this.emit(CSS_FULLSCREEN_CHANGE, false);
|
|
1147
|
+
}
|
|
1148
|
+
}, {
|
|
1149
|
+
key: "getRotateFullscreen",
|
|
1150
|
+
value: function getRotateFullscreen() {
|
|
1151
|
+
var el = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : this.config.fullscreenTarget;
|
|
1152
|
+
if (this.cssfullscreen) {
|
|
1153
|
+
this.exitCssFullscreen(el);
|
|
1154
|
+
}
|
|
1155
|
+
var _class = el ? "".concat(STATE_CLASS.INNER_FULLSCREEN, " ").concat(STATE_CLASS.ROTATE_FULLSCREEN) : STATE_CLASS.ROTATE_FULLSCREEN;
|
|
1156
|
+
this._fullscreenEl = el || this.root;
|
|
1157
|
+
this.changeFullStyle(this.root, el, _class, STATE_CLASS.PARENT_ROTATE_FULLSCREEN);
|
|
1158
|
+
this.isRotateFullscreen = true;
|
|
1159
|
+
this.fullscreen = true;
|
|
1160
|
+
this.setRotateDeg(90);
|
|
1161
|
+
this._rootStyle = this.root.getAttribute("style");
|
|
1162
|
+
this.root.style.width = "".concat(window.innerHeight, "px");
|
|
1163
|
+
this.emit(FULLSCREEN_CHANGE, true);
|
|
1164
|
+
}
|
|
1165
|
+
}, {
|
|
1166
|
+
key: "exitRotateFullscreen",
|
|
1167
|
+
value: function exitRotateFullscreen(el) {
|
|
1168
|
+
var _class = this._fullscreenEl !== this.root ? "".concat(STATE_CLASS.INNER_FULLSCREEN, " ").concat(STATE_CLASS.ROTATE_FULLSCREEN) : STATE_CLASS.ROTATE_FULLSCREEN;
|
|
1169
|
+
this.recoverFullStyle(this.root, this._fullscreenEl, _class, STATE_CLASS.PARENT_ROTATE_FULLSCREEN);
|
|
1170
|
+
this.isRotateFullscreen = false;
|
|
1171
|
+
this.fullscreen = false;
|
|
1172
|
+
this.setRotateDeg(0);
|
|
1173
|
+
this.emit(FULLSCREEN_CHANGE, false);
|
|
1174
|
+
if (this._rootStyle) {
|
|
1175
|
+
this.root.style.style = this._rootStyle;
|
|
1176
|
+
this._rootStyle = false;
|
|
1177
|
+
}
|
|
1178
|
+
}
|
|
1179
|
+
}, {
|
|
1180
|
+
key: "setRotateDeg",
|
|
1181
|
+
value: function setRotateDeg(deg) {
|
|
1182
|
+
if (window.orientation === 90 || window.orientation === -90) {
|
|
1183
|
+
this.rotateDeg = 0;
|
|
1184
|
+
} else {
|
|
1185
|
+
this.rotateDeg = deg;
|
|
1186
|
+
}
|
|
1187
|
+
}
|
|
882
1188
|
}, {
|
|
883
1189
|
key: "focus",
|
|
884
1190
|
value: function focus() {
|
|
@@ -913,7 +1219,7 @@ var Player = /* @__PURE__ */ function(_MediaProxy) {
|
|
|
913
1219
|
}, {
|
|
914
1220
|
key: "onFocus",
|
|
915
1221
|
value: function onFocus() {
|
|
916
|
-
var
|
|
1222
|
+
var _this21 = this;
|
|
917
1223
|
var data = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {
|
|
918
1224
|
autoHide: true,
|
|
919
1225
|
delay: 3e3
|
|
@@ -922,7 +1228,7 @@ var Player = /* @__PURE__ */ function(_MediaProxy) {
|
|
|
922
1228
|
this.isActive = true;
|
|
923
1229
|
this.removeClass(STATE_CLASS.INACTIVE);
|
|
924
1230
|
if (this.userTimer) {
|
|
925
|
-
clearTimeout(this, this.userTimer);
|
|
1231
|
+
util.clearTimeout(this, this.userTimer);
|
|
926
1232
|
this.userTimer = null;
|
|
927
1233
|
}
|
|
928
1234
|
if (data.isLock !== void 0) {
|
|
@@ -930,15 +1236,15 @@ var Player = /* @__PURE__ */ function(_MediaProxy) {
|
|
|
930
1236
|
}
|
|
931
1237
|
if (data.autoHide === false || data.isLock === true || innerStates.isActiveLocked) {
|
|
932
1238
|
if (this.userTimer) {
|
|
933
|
-
clearTimeout(this, this.userTimer);
|
|
1239
|
+
util.clearTimeout(this, this.userTimer);
|
|
934
1240
|
this.userTimer = null;
|
|
935
1241
|
}
|
|
936
1242
|
return;
|
|
937
1243
|
}
|
|
938
1244
|
var time = data && data.delay ? data.delay : this.config.inactive;
|
|
939
|
-
this.userTimer = setTimeout(this, function() {
|
|
940
|
-
|
|
941
|
-
|
|
1245
|
+
this.userTimer = util.setTimeout(this, function() {
|
|
1246
|
+
_this21.userTimer = null;
|
|
1247
|
+
_this21.blur();
|
|
942
1248
|
}, time);
|
|
943
1249
|
}
|
|
944
1250
|
}, {
|
|
@@ -966,7 +1272,15 @@ var Player = /* @__PURE__ */ function(_MediaProxy) {
|
|
|
966
1272
|
this.removeClass(STATE_CLASS.ERROR);
|
|
967
1273
|
this.removeClass(STATE_CLASS.LOADING);
|
|
968
1274
|
this.isCanplay = true;
|
|
969
|
-
this.waitTimer && clearTimeout(this, this.waitTimer);
|
|
1275
|
+
this.waitTimer && util.clearTimeout(this, this.waitTimer);
|
|
1276
|
+
}
|
|
1277
|
+
}, {
|
|
1278
|
+
key: "onDurationchange",
|
|
1279
|
+
value: function onDurationchange() {
|
|
1280
|
+
if (this.__startTime > 0 && this.duration > 0) {
|
|
1281
|
+
this.currentTime = this.__startTime;
|
|
1282
|
+
this.__startTime = -1;
|
|
1283
|
+
}
|
|
970
1284
|
}
|
|
971
1285
|
}, {
|
|
972
1286
|
key: "onLoadeddata",
|
|
@@ -997,7 +1311,7 @@ var Player = /* @__PURE__ */ function(_MediaProxy) {
|
|
|
997
1311
|
this.updateAcc("pause");
|
|
998
1312
|
if (!this.config.closePauseVideoFocus) {
|
|
999
1313
|
if (this.userTimer) {
|
|
1000
|
-
clearTimeout(this, this.userTimer);
|
|
1314
|
+
util.clearTimeout(this, this.userTimer);
|
|
1001
1315
|
this.userTimer = null;
|
|
1002
1316
|
}
|
|
1003
1317
|
this.focus();
|
|
@@ -1013,12 +1327,12 @@ var Player = /* @__PURE__ */ function(_MediaProxy) {
|
|
|
1013
1327
|
}, {
|
|
1014
1328
|
key: "onError",
|
|
1015
1329
|
value: function onError() {
|
|
1016
|
-
var _this21 = this;
|
|
1017
1330
|
this.isError = true;
|
|
1018
1331
|
this.updateAcc("error");
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1332
|
+
this.removeClass(STATE_CLASS.NOT_ALLOW_AUTOPLAY);
|
|
1333
|
+
this.removeClass(STATE_CLASS.NO_START);
|
|
1334
|
+
this.removeClass(STATE_CLASS.ENTER);
|
|
1335
|
+
this.removeClass(STATE_CLASS.LOADING);
|
|
1022
1336
|
this.addClass(STATE_CLASS.ERROR);
|
|
1023
1337
|
}
|
|
1024
1338
|
}, {
|
|
@@ -1035,7 +1349,7 @@ var Player = /* @__PURE__ */ function(_MediaProxy) {
|
|
|
1035
1349
|
value: function onSeeked() {
|
|
1036
1350
|
this.isSeeking = false;
|
|
1037
1351
|
if (this.waitTimer) {
|
|
1038
|
-
clearTimeout(this, this.waitTimer);
|
|
1352
|
+
util.clearTimeout(this, this.waitTimer);
|
|
1039
1353
|
}
|
|
1040
1354
|
this.removeClass(STATE_CLASS.LOADING);
|
|
1041
1355
|
this.removeClass(STATE_CLASS.SEEKING);
|
|
@@ -1045,12 +1359,12 @@ var Player = /* @__PURE__ */ function(_MediaProxy) {
|
|
|
1045
1359
|
value: function onWaiting() {
|
|
1046
1360
|
var _this22 = this;
|
|
1047
1361
|
if (this.waitTimer) {
|
|
1048
|
-
clearTimeout(this, this.waitTimer);
|
|
1362
|
+
util.clearTimeout(this, this.waitTimer);
|
|
1049
1363
|
}
|
|
1050
1364
|
this.updateAcc("waiting");
|
|
1051
|
-
this.waitTimer = setTimeout(this, function() {
|
|
1365
|
+
this.waitTimer = util.setTimeout(this, function() {
|
|
1052
1366
|
_this22.addClass(STATE_CLASS.LOADING);
|
|
1053
|
-
clearTimeout(_this22, _this22.waitTimer);
|
|
1367
|
+
util.clearTimeout(_this22, _this22.waitTimer);
|
|
1054
1368
|
_this22.waitTimer = null;
|
|
1055
1369
|
}, this.config.minWaitDelay);
|
|
1056
1370
|
}
|
|
@@ -1074,7 +1388,7 @@ var Player = /* @__PURE__ */ function(_MediaProxy) {
|
|
|
1074
1388
|
!this._videoHeight && this.media.videoHeight && this.resize();
|
|
1075
1389
|
if ((this.waitTimer || this.hasClass(STATE_CLASS.LOADING)) && this.media.readyState > 2) {
|
|
1076
1390
|
this.removeClass(STATE_CLASS.LOADING);
|
|
1077
|
-
clearTimeout(this, this.waitTimer);
|
|
1391
|
+
util.clearTimeout(this, this.waitTimer);
|
|
1078
1392
|
this.waitTimer = null;
|
|
1079
1393
|
}
|
|
1080
1394
|
if (!this.paused && this.state < STATES.RUNNING && this.duration) {
|
|
@@ -1088,7 +1402,7 @@ var Player = /* @__PURE__ */ function(_MediaProxy) {
|
|
|
1088
1402
|
}, {
|
|
1089
1403
|
key: "onVolumechange",
|
|
1090
1404
|
value: function onVolumechange() {
|
|
1091
|
-
typeOf(this.config.volume) === "Number" && (this.config.volume = this.volume);
|
|
1405
|
+
util.typeOf(this.config.volume) === "Number" && (this.config.volume = this.volume);
|
|
1092
1406
|
}
|
|
1093
1407
|
}, {
|
|
1094
1408
|
key: "onRatechange",
|
|
@@ -1101,8 +1415,8 @@ var Player = /* @__PURE__ */ function(_MediaProxy) {
|
|
|
1101
1415
|
if (!this.media || !action || !event) {
|
|
1102
1416
|
return;
|
|
1103
1417
|
}
|
|
1104
|
-
var eventType = typeOf(event) === "String" ? event : event.type || "";
|
|
1105
|
-
if (params.props && typeOf(params.props) !== "Array") {
|
|
1418
|
+
var eventType = util.typeOf(event) === "String" ? event : event.type || "";
|
|
1419
|
+
if (params.props && util.typeOf(params.props) !== "Array") {
|
|
1106
1420
|
params.props = [params.props];
|
|
1107
1421
|
}
|
|
1108
1422
|
this.emit(USER_ACTION, _objectSpread2({
|
|
@@ -1142,6 +1456,77 @@ var Player = /* @__PURE__ */ function(_MediaProxy) {
|
|
|
1142
1456
|
}
|
|
1143
1457
|
return false;
|
|
1144
1458
|
}
|
|
1459
|
+
}, {
|
|
1460
|
+
key: "resizePosition",
|
|
1461
|
+
value: function resizePosition() {
|
|
1462
|
+
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;
|
|
1463
|
+
if (rotate < 0 && !vy && !vx) {
|
|
1464
|
+
return;
|
|
1465
|
+
}
|
|
1466
|
+
var _pi = this.videoPos._pi;
|
|
1467
|
+
if (!_pi && this.media.videoHeight) {
|
|
1468
|
+
_pi = this.media.videoWidth / this.media.videoHeight * 100;
|
|
1469
|
+
}
|
|
1470
|
+
if (!_pi) {
|
|
1471
|
+
return;
|
|
1472
|
+
}
|
|
1473
|
+
this.videoPos.pi = _pi;
|
|
1474
|
+
var _pos = {
|
|
1475
|
+
rotate
|
|
1476
|
+
};
|
|
1477
|
+
var offsetY = 0;
|
|
1478
|
+
var offsetX = 0;
|
|
1479
|
+
var scale = 1;
|
|
1480
|
+
var _t = rotate < 0 ? 0 : Math.abs(rotate / 90);
|
|
1481
|
+
var root = this.root, innerContainer = this.innerContainer;
|
|
1482
|
+
var width = root.offsetWidth;
|
|
1483
|
+
var height = innerContainer ? innerContainer.offsetHeight : root.offsetHeight;
|
|
1484
|
+
var rHeight = height;
|
|
1485
|
+
var rWidth = width;
|
|
1486
|
+
if (_t % 2 === 0) {
|
|
1487
|
+
scale = h > 0 ? 100 / h : w > 0 ? 100 / w : 1;
|
|
1488
|
+
_pos.scale = scale;
|
|
1489
|
+
offsetY = vy > 0 ? (100 - h) / 2 - vy : 0;
|
|
1490
|
+
_pos.y = _t === 2 ? 0 - offsetY : offsetY;
|
|
1491
|
+
offsetX = vx > 0 ? (100 - w) / 2 - vx : 0;
|
|
1492
|
+
_pos.x = _t === 2 ? 0 - offsetX : offsetX;
|
|
1493
|
+
this.media.style.width = "".concat(rWidth, "px");
|
|
1494
|
+
this.media.style.height = "".concat(rHeight, "px");
|
|
1495
|
+
} else if (_t % 2 === 1) {
|
|
1496
|
+
rWidth = height;
|
|
1497
|
+
rHeight = width;
|
|
1498
|
+
var offset = height - width;
|
|
1499
|
+
offsetX = -offset / 2 / rWidth * 100;
|
|
1500
|
+
_pos.x = _t === 3 ? offsetX + vy / 2 : offsetX - vy / 2;
|
|
1501
|
+
offsetY = offset / 2 / rHeight * 100;
|
|
1502
|
+
_pos.y = _t === 3 ? offsetY + vx / 2 : offsetY - vx / 2;
|
|
1503
|
+
_pos.scale = scale;
|
|
1504
|
+
this.media.style.width = "".concat(rWidth, "px");
|
|
1505
|
+
this.media.style.height = "".concat(rHeight, "px");
|
|
1506
|
+
}
|
|
1507
|
+
var formStyle = util.getTransformStyle(_pos, this.media.style.transform || this.media.style.webkitTransform);
|
|
1508
|
+
this.media.style.transform = formStyle;
|
|
1509
|
+
this.media.style.webkitTransform = formStyle;
|
|
1510
|
+
}
|
|
1511
|
+
}, {
|
|
1512
|
+
key: "position",
|
|
1513
|
+
value: function position() {
|
|
1514
|
+
var pos = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {
|
|
1515
|
+
h: 0,
|
|
1516
|
+
y: 0,
|
|
1517
|
+
x: 0,
|
|
1518
|
+
w: 0
|
|
1519
|
+
};
|
|
1520
|
+
if (!this.media || !pos || !pos.h) {
|
|
1521
|
+
return;
|
|
1522
|
+
}
|
|
1523
|
+
var videoPos = this.videoPos;
|
|
1524
|
+
videoPos.h = pos.h * 100 || 0;
|
|
1525
|
+
videoPos.w = pos.w * 100 || 0;
|
|
1526
|
+
videoPos.vx = pos.x * 100 || 0;
|
|
1527
|
+
videoPos.vy = pos.y * 100 || 0;
|
|
1528
|
+
this.resizePosition();
|
|
1529
|
+
}
|
|
1145
1530
|
}, {
|
|
1146
1531
|
key: "setConfig",
|
|
1147
1532
|
value: function setConfig(config) {
|
|
@@ -1153,7 +1538,7 @@ var Player = /* @__PURE__ */ function(_MediaProxy) {
|
|
|
1153
1538
|
if (key !== "plugins") {
|
|
1154
1539
|
_this24.config[key] = config[key];
|
|
1155
1540
|
var plugin = _this24.plugins[key.toLowerCase()];
|
|
1156
|
-
if (plugin && typeOf(plugin.setConfig) === "Function") {
|
|
1541
|
+
if (plugin && util.typeOf(plugin.setConfig) === "Function") {
|
|
1157
1542
|
plugin.setConfig(config[key]);
|
|
1158
1543
|
}
|
|
1159
1544
|
}
|
|
@@ -1175,6 +1560,61 @@ var Player = /* @__PURE__ */ function(_MediaProxy) {
|
|
|
1175
1560
|
}, {
|
|
1176
1561
|
key: "resize",
|
|
1177
1562
|
value: function resize() {
|
|
1563
|
+
var _this26 = this;
|
|
1564
|
+
if (!this.media || !this.root) {
|
|
1565
|
+
return;
|
|
1566
|
+
}
|
|
1567
|
+
var containerSize = this.root.getBoundingClientRect();
|
|
1568
|
+
this.sizeInfo.width = containerSize.width;
|
|
1569
|
+
this.sizeInfo.height = containerSize.height;
|
|
1570
|
+
this.sizeInfo.left = containerSize.left;
|
|
1571
|
+
this.sizeInfo.top = containerSize.top;
|
|
1572
|
+
var _this$media = this.media, videoWidth = _this$media.videoWidth, videoHeight = _this$media.videoHeight;
|
|
1573
|
+
var _this$config7 = this.config, fitVideoSize = _this$config7.fitVideoSize, videoFillMode = _this$config7.videoFillMode;
|
|
1574
|
+
if (videoFillMode === "fill" || videoFillMode === "cover" || videoFillMode === "contain") {
|
|
1575
|
+
this.setAttribute("data-xgfill", videoFillMode);
|
|
1576
|
+
}
|
|
1577
|
+
if (!videoHeight || !videoWidth) {
|
|
1578
|
+
return;
|
|
1579
|
+
}
|
|
1580
|
+
this._videoHeight = videoHeight;
|
|
1581
|
+
this._videoWidth = videoWidth;
|
|
1582
|
+
var controlsHeight = this.controls && this.innerContainer ? this.controls.root.getBoundingClientRect().height : 0;
|
|
1583
|
+
var width = containerSize.width;
|
|
1584
|
+
var height = containerSize.height - controlsHeight;
|
|
1585
|
+
var videoFit = parseInt(videoWidth / videoHeight * 1e3, 10);
|
|
1586
|
+
var fit = parseInt(width / height * 1e3, 10);
|
|
1587
|
+
var rWidth = width;
|
|
1588
|
+
var rHeight = height;
|
|
1589
|
+
var _style = {};
|
|
1590
|
+
if (fitVideoSize === "auto" && fit > videoFit || fitVideoSize === "fixWidth") {
|
|
1591
|
+
rHeight = width / videoFit * 1e3;
|
|
1592
|
+
if (this.config.fluid) {
|
|
1593
|
+
_style.paddingTop = "".concat(rHeight * 100 / rWidth, "%");
|
|
1594
|
+
} else {
|
|
1595
|
+
_style.height = "".concat(rHeight + controlsHeight, "px");
|
|
1596
|
+
}
|
|
1597
|
+
} else if (fitVideoSize === "auto" && fit < videoFit || fitVideoSize === "fixHeight") {
|
|
1598
|
+
rWidth = videoFit * height / 1e3;
|
|
1599
|
+
_style.width = "".concat(rWidth, "px");
|
|
1600
|
+
}
|
|
1601
|
+
if (!this.fullscreen && !this.cssfullscreen) {
|
|
1602
|
+
Object.keys(_style).forEach(function(key) {
|
|
1603
|
+
_this26.root.style[key] = _style[key];
|
|
1604
|
+
});
|
|
1605
|
+
}
|
|
1606
|
+
if (videoFillMode === "fillHeight" && fit < videoFit || videoFillMode === "fillWidth" && fit > videoFit) {
|
|
1607
|
+
this.setAttribute("data-xgfill", "cover");
|
|
1608
|
+
}
|
|
1609
|
+
var data = {
|
|
1610
|
+
videoScale: videoFit,
|
|
1611
|
+
vWidth: rWidth,
|
|
1612
|
+
vHeight: rHeight,
|
|
1613
|
+
cWidth: rWidth,
|
|
1614
|
+
cHeight: rHeight + controlsHeight
|
|
1615
|
+
};
|
|
1616
|
+
this.resizePosition();
|
|
1617
|
+
this.emit(VIDEO_RESIZE, data);
|
|
1178
1618
|
}
|
|
1179
1619
|
}, {
|
|
1180
1620
|
key: "updateObjectPosition",
|
|
@@ -1197,7 +1637,7 @@ var Player = /* @__PURE__ */ function(_MediaProxy) {
|
|
|
1197
1637
|
key: "preProcessUrl",
|
|
1198
1638
|
value: function preProcessUrl(url, ext) {
|
|
1199
1639
|
var preProcessUrl2 = this.config.preProcessUrl;
|
|
1200
|
-
return !isBlob(url) && preProcessUrl2 && typeof preProcessUrl2 === "function" ? preProcessUrl2(url, ext) : {
|
|
1640
|
+
return !util.isBlob(url) && preProcessUrl2 && typeof preProcessUrl2 === "function" ? preProcessUrl2(url, ext) : {
|
|
1201
1641
|
url
|
|
1202
1642
|
};
|
|
1203
1643
|
}
|
|
@@ -1251,15 +1691,15 @@ var Player = /* @__PURE__ */ function(_MediaProxy) {
|
|
|
1251
1691
|
return this.config.definition.list || [];
|
|
1252
1692
|
},
|
|
1253
1693
|
set: function set(list) {
|
|
1254
|
-
var
|
|
1694
|
+
var _this27 = this;
|
|
1255
1695
|
var definition = this.config.definition;
|
|
1256
1696
|
var curDef = null;
|
|
1257
1697
|
var targetDef = null;
|
|
1258
1698
|
definition.list = list;
|
|
1259
1699
|
this.emit("resourceReady", list);
|
|
1260
1700
|
list.forEach(function(item) {
|
|
1261
|
-
var
|
|
1262
|
-
if (((
|
|
1701
|
+
var _this27$curDefinition;
|
|
1702
|
+
if (((_this27$curDefinition = _this27.curDefinition) === null || _this27$curDefinition === void 0 ? void 0 : _this27$curDefinition.definition) === item.definition) {
|
|
1263
1703
|
curDef = item;
|
|
1264
1704
|
}
|
|
1265
1705
|
if (definition.defaultDefinition === item.definition) {
|
|
@@ -1294,6 +1734,41 @@ var Player = /* @__PURE__ */ function(_MediaProxy) {
|
|
|
1294
1734
|
}
|
|
1295
1735
|
return ret;
|
|
1296
1736
|
}
|
|
1737
|
+
}, {
|
|
1738
|
+
key: "controls",
|
|
1739
|
+
get: function get() {
|
|
1740
|
+
return this.plugins.controls;
|
|
1741
|
+
}
|
|
1742
|
+
}, {
|
|
1743
|
+
key: "lang",
|
|
1744
|
+
get: function get() {
|
|
1745
|
+
return this.config.lang;
|
|
1746
|
+
},
|
|
1747
|
+
set: function set(lang) {
|
|
1748
|
+
var result = I18N.langKeys.filter(function(key) {
|
|
1749
|
+
return key === lang;
|
|
1750
|
+
});
|
|
1751
|
+
if (result.length === 0 && lang !== "zh") {
|
|
1752
|
+
console.error("Sorry, set lang fail, because the language [".concat(lang, "] is not supported now, list of all supported languages is [").concat(I18N.langKeys.join(), "] "));
|
|
1753
|
+
return;
|
|
1754
|
+
}
|
|
1755
|
+
this.config.lang = lang;
|
|
1756
|
+
pluginsManager.setLang(lang, this);
|
|
1757
|
+
}
|
|
1758
|
+
}, {
|
|
1759
|
+
key: "i18n",
|
|
1760
|
+
get: function get() {
|
|
1761
|
+
var _l = this.config.lang;
|
|
1762
|
+
if (_l === "zh") {
|
|
1763
|
+
_l = "zh-cn";
|
|
1764
|
+
}
|
|
1765
|
+
return this.__i18n.lang[_l] || this.__i18n.lang.en;
|
|
1766
|
+
}
|
|
1767
|
+
}, {
|
|
1768
|
+
key: "i18nKeys",
|
|
1769
|
+
get: function get() {
|
|
1770
|
+
return this.__i18n.textKeys || {};
|
|
1771
|
+
}
|
|
1297
1772
|
}, {
|
|
1298
1773
|
key: "version",
|
|
1299
1774
|
get: function get() {
|
|
@@ -1355,6 +1830,19 @@ var Player = /* @__PURE__ */ function(_MediaProxy) {
|
|
|
1355
1830
|
set: function set(value) {
|
|
1356
1831
|
this.config.zoom = value;
|
|
1357
1832
|
}
|
|
1833
|
+
}, {
|
|
1834
|
+
key: "videoRotateDeg",
|
|
1835
|
+
get: function get() {
|
|
1836
|
+
return this.videoPos.rotate;
|
|
1837
|
+
},
|
|
1838
|
+
set: function set(val) {
|
|
1839
|
+
val = util.convertDeg(val);
|
|
1840
|
+
if (val % 90 !== 0 || val === this.videoPos.rotate) {
|
|
1841
|
+
return;
|
|
1842
|
+
}
|
|
1843
|
+
this.videoPos.rotate = val;
|
|
1844
|
+
this.resizePosition();
|
|
1845
|
+
}
|
|
1358
1846
|
}, {
|
|
1359
1847
|
key: "avgSpeed",
|
|
1360
1848
|
get: function get() {
|
|
@@ -1455,6 +1943,24 @@ var Player = /* @__PURE__ */ function(_MediaProxy) {
|
|
|
1455
1943
|
value: function probeConfigSupported(info) {
|
|
1456
1944
|
return sniffer.probeConfigSupported(info);
|
|
1457
1945
|
}
|
|
1946
|
+
}, {
|
|
1947
|
+
key: "install",
|
|
1948
|
+
value: function install(name, descriptor) {
|
|
1949
|
+
if (!Player2.plugins) {
|
|
1950
|
+
Player2.plugins = {};
|
|
1951
|
+
}
|
|
1952
|
+
if (!Player2.plugins[name]) {
|
|
1953
|
+
Player2.plugins[name] = descriptor;
|
|
1954
|
+
}
|
|
1955
|
+
}
|
|
1956
|
+
}, {
|
|
1957
|
+
key: "use",
|
|
1958
|
+
value: function use(name, descriptor) {
|
|
1959
|
+
if (!Player2.plugins) {
|
|
1960
|
+
Player2.plugins = {};
|
|
1961
|
+
}
|
|
1962
|
+
Player2.plugins[name] = descriptor;
|
|
1963
|
+
}
|
|
1458
1964
|
}]);
|
|
1459
1965
|
return Player2;
|
|
1460
1966
|
}(MediaProxy);
|