xgplayer 3.0.10-alpha.0 → 3.0.10-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.
@@ -1,6 +1,9 @@
1
+ /**
2
+ * @typedef { string | MediaStream | Array<{src: string, type?:string, [propName: string]: any}> } IUrl
3
+ */
1
4
  /**
2
5
  * @typedef {{
3
- * url: any,
6
+ * url: IUrl,
4
7
  * definition: any,
5
8
  * bitrate?: number,
6
9
  * bandwidth?: number,
@@ -13,7 +16,7 @@
13
16
  * @typedef { {
14
17
  * id?: string,
15
18
  * el?: HTMLElement,
16
- * url?: any,
19
+ * url?: IUrl,
17
20
  * domEventType?: 'default' | 'touch' | 'mouse',
18
21
  * nullUrlStart?: boolean,
19
22
  * width?: number | string,
@@ -50,6 +53,7 @@
50
53
  * miniprogress?: boolean,
51
54
  * disableSwipeHandler?: () => any,
52
55
  * enableSwipeHandler?: () => any,
56
+ * preProcessUrl?: (url: IUrl, ext?: { [propName: string]: any }) => { url: IUrl, [propName: string]: any },
53
57
  * ignores?: Array<'cssfullscreen' | 'screenshot' | 'pip' | 'miniscreen' | 'keyboard' | 'download' | 'playbackrate' | 'time' | 'definition' | 'error' | 'fullscreen' | 'loading' | 'mobile' | 'pc' | 'play' | 'poster' | 'progress' | 'replay' | 'start' | 'volume' | string>,
54
58
  * inactive?: number,
55
59
  * lang?: string,
@@ -98,9 +102,14 @@
98
102
  * @returns { IPlayerOptions }
99
103
  */
100
104
  export default function getDefaultConfig(): IPlayerOptions;
105
+ export type IUrl = string | MediaStream | {
106
+ [propName: string]: any;
107
+ src: string;
108
+ type?: string;
109
+ }[];
101
110
  export type IDefinition = {
102
111
  [propName: string]: any;
103
- url: any;
112
+ url: IUrl;
104
113
  definition: any;
105
114
  bitrate?: number;
106
115
  bandwidth?: number;
@@ -115,7 +124,7 @@ export type IPlayerOptions = {
115
124
  [propName: string]: any;
116
125
  id?: string;
117
126
  el?: HTMLElement;
118
- url?: any;
127
+ url?: IUrl;
119
128
  domEventType?: 'default' | 'touch' | 'mouse';
120
129
  nullUrlStart?: boolean;
121
130
  width?: number | string;
@@ -158,6 +167,12 @@ export type IPlayerOptions = {
158
167
  miniprogress?: boolean;
159
168
  disableSwipeHandler?: () => any;
160
169
  enableSwipeHandler?: () => any;
170
+ preProcessUrl?: (url: IUrl, ext?: {
171
+ [propName: string]: any;
172
+ }) => {
173
+ [propName: string]: any;
174
+ url: IUrl;
175
+ };
161
176
  ignores?: Array<'cssfullscreen' | 'screenshot' | 'pip' | 'miniscreen' | 'keyboard' | 'download' | 'playbackrate' | 'time' | 'definition' | 'error' | 'fullscreen' | 'loading' | 'mobile' | 'pc' | 'play' | 'poster' | 'progress' | 'replay' | 'start' | 'volume' | string>;
162
177
  inactive?: number;
163
178
  lang?: string;
@@ -42,6 +42,7 @@ function getDefaultConfig() {
42
42
  },
43
43
  enableSwipeHandler: function enableSwipeHandler() {
44
44
  },
45
+ preProcessUrl: null,
45
46
  ignores: [],
46
47
  whitelist: [],
47
48
  inactive: 3e3,
package/es/mediaProxy.js CHANGED
@@ -541,7 +541,7 @@ var MediaProxy = /* @__PURE__ */ function(_EventEmitter) {
541
541
  this.emit(WAITING);
542
542
  this._currentTime = 0;
543
543
  this._duration = 0;
544
- if (/^blob/.test(this.media.currentSrc) || /^blob/.test(this.media.src)) {
544
+ if (util.isMSE(this.media)) {
545
545
  this.onWaiting();
546
546
  return;
547
547
  }
package/es/player.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export type IPlayerOptions = import('./defaultConfig').IPlayerOptions;
2
2
  export type IDefinition = import('./defaultConfig').IDefinition;
3
+ export type IUrl = import('./defaultConfig').IUrl;
3
4
  declare class Player extends MediaProxy {
4
5
  /**
5
6
  * @type {number}
@@ -642,6 +643,15 @@ declare class Player extends MediaProxy {
642
643
  * @param { number } newState
643
644
  */
644
645
  protected setState(newState: number): void;
646
+ /**
647
+ * @description url preprocessing
648
+ * @param { IUrl } url
649
+ * @param { {[propName: string]: any} } [ext]
650
+ * @returns { url: IUrl, [propName: string]: any }
651
+ */
652
+ preProcessUrl(url: IUrl, ext?: {
653
+ [propName: string]: any;
654
+ }): import("./defaultConfig").IUrl;
645
655
  /**
646
656
  * @type { number }
647
657
  */
package/es/player.js CHANGED
@@ -389,8 +389,7 @@ var Player = /* @__PURE__ */ function(_MediaProxy) {
389
389
  var readyState = this.media.readyState;
390
390
  XG_DEBUG.logInfo("_startInit readyState", readyState);
391
391
  if (this.config.autoplay) {
392
- !(/^blob/.test(this.media.currentSrc) || /^blob/.test(this.media.src)) && this.load();
393
- (sniffer.os.isIpad || sniffer.os.isPhone) && this.mediaPlay();
392
+ !util.isMSE(this.media) && this.load()(sniffer.os.isIpad || sniffer.os.isPhone) && this.mediaPlay();
394
393
  }
395
394
  if (readyState >= 2) {
396
395
  this.canPlayFunc();
@@ -617,7 +616,8 @@ var Player = /* @__PURE__ */ function(_MediaProxy) {
617
616
  if (!url) {
618
617
  url = _this8.url || _this8.config.url;
619
618
  }
620
- var ret = _this8._startInit(url);
619
+ var _furl = _this8.preProcessUrl(url);
620
+ var ret = _this8._startInit(_furl.url);
621
621
  return ret;
622
622
  }).catch(function(e) {
623
623
  e.fileName = "player";
@@ -634,6 +634,7 @@ var Player = /* @__PURE__ */ function(_MediaProxy) {
634
634
  if (util.typeOf(url) === "Object") {
635
635
  _src = url.url;
636
636
  }
637
+ _src = this.preProcessUrl(_src).url;
637
638
  var curTime = this.currentTime;
638
639
  var isPaused = this.paused && !this.isError;
639
640
  this.src = _src;
@@ -1608,6 +1609,14 @@ var Player = /* @__PURE__ */ function(_MediaProxy) {
1608
1609
  XG_DEBUG.logInfo("setState", "state from:".concat(STATE_ARRAY[this.state], " to:").concat(STATE_ARRAY[newState]));
1609
1610
  this._state = newState;
1610
1611
  }
1612
+ }, {
1613
+ key: "preProcessUrl",
1614
+ value: function preProcessUrl(url, ext) {
1615
+ var preProcessUrl2 = this.config.preProcessUrl;
1616
+ return !util.isBlob(url) && preProcessUrl2 && typeof preProcessUrl2 === "function" ? preProcessUrl2(url, ext) : {
1617
+ url
1618
+ };
1619
+ }
1611
1620
  }, {
1612
1621
  key: "state",
1613
1622
  get: function get() {
@@ -175,7 +175,7 @@ var DynamicBg = /* @__PURE__ */ function(_Plugin) {
175
175
  return null;
176
176
  }
177
177
  var _tVideo = video && video instanceof window.HTMLVideoElement ? video : video.canvas ? video.canvas : video.flyVideo ? video.flyVideo : null;
178
- if (_tVideo && !(sniffer.browser === "safari" && (/^blob/.test(_tVideo.currentSrc) || /^blob/.test(_tVideo.src)))) {
178
+ if (_tVideo && !(sniffer.browser === "safari" && util.isMSE(_tVideo))) {
179
179
  return _tVideo;
180
180
  }
181
181
  var _tagName = _tVideo ? _tVideo.tagName.toLowerCase() : "";
@@ -244,6 +244,7 @@ declare namespace util {
244
244
  * @returns { Boolean }
245
245
  */
246
246
  function isMSE(video: HTMLElement | HTMLVideoElement | HTMLAudioElement): boolean;
247
+ function isBlob(url: any): boolean;
247
248
  /**
248
249
  * @param { number } did
249
250
  * @returns { string }
package/es/utils/util.js CHANGED
@@ -534,6 +534,9 @@ util.isMSE = function(video) {
534
534
  }
535
535
  return /^blob/.test(video.currentSrc) || /^blob/.test(video.src);
536
536
  };
537
+ util.isBlob = function(url) {
538
+ return /^blob/.test(url);
539
+ };
537
540
  util.generateSessionId = function() {
538
541
  var did = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 0;
539
542
  var d = new Date().getTime();
package/es/version.js CHANGED
@@ -1,2 +1,2 @@
1
- var version = "3.0.10-alpha.0";
1
+ var version = "3.0.10-alpha.2";
2
2
  export { version as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xgplayer",
3
- "version": "3.0.10-alpha.0",
3
+ "version": "3.0.10-alpha.2",
4
4
  "description": "video player",
5
5
  "main": "dist/index.min.js",
6
6
  "module": "es/index.js",
@@ -43,7 +43,7 @@
43
43
  "delegate": "^3.2.0",
44
44
  "downloadjs": "1.4.7",
45
45
  "eventemitter3": "^4.0.7",
46
- "xgplayer-subtitles": "3.0.10-alpha.0"
46
+ "xgplayer-subtitles": "3.0.10-alpha.2"
47
47
  },
48
48
  "peerDependencies": {
49
49
  "core-js": ">=3.12.1"