@clappr/hlsjs-playback 1.0.1 → 1.1.0

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.
@@ -25676,9 +25676,9 @@ EventEmitter.EventEmitter = EventEmitter;
25676
25676
  var HLSJS = /*@__PURE__*/getDefaultExportFromCjs(hls.exports);
25677
25677
 
25678
25678
  var now = Utils.now,
25679
- assign = Utils.assign,
25680
25679
  listContainsIgnoreCase = Utils.listContainsIgnoreCase;
25681
25680
  var AUTO = -1;
25681
+ var DEFAULT_RECOVER_ATTEMPTS = 16;
25682
25682
  Events.register('PLAYBACK_FRAGMENT_CHANGED');
25683
25683
  Events.register('PLAYBACK_FRAGMENT_PARSING_METADATA');
25684
25684
  var HlsjsPlayback = /*#__PURE__*/function (_HTML5Video) {
@@ -25691,49 +25691,8 @@ var HlsjsPlayback = /*#__PURE__*/function (_HTML5Video) {
25691
25691
  args[_key] = arguments[_key];
25692
25692
  }
25693
25693
  _this = _super.call.apply(_super, [this].concat(args));
25694
- // backwards compatibility (TODO: remove on 0.3.0)
25695
- _this.options.playback = _objectSpread2(_objectSpread2({}, _this.options), _this.options.playback);
25696
25694
  _this.options.hlsPlayback = _objectSpread2(_objectSpread2({}, _this.defaultOptions), _this.options.hlsPlayback);
25697
- _this._minDvrSize = typeof _this.options.hlsMinimumDvrSize === 'undefined' ? 60 : _this.options.hlsMinimumDvrSize;
25698
- // The size of the start time extrapolation window measured as a multiple of segments.
25699
- // Should be 2 or higher, or 0 to disable. Should only need to be increased above 2 if more than one segment is
25700
- // removed from the start of the playlist at a time. E.g if the playlist is cached for 10 seconds and new chunks are
25701
- // added/removed every 5.
25702
- _this._extrapolatedWindowNumSegments = !_this.options.playback || typeof _this.options.playback.extrapolatedWindowNumSegments === 'undefined' ? 2 : _this.options.playback.extrapolatedWindowNumSegments;
25703
- _this._playbackType = Playback.VOD;
25704
- _this._lastTimeUpdate = {
25705
- current: 0,
25706
- total: 0
25707
- };
25708
- _this._lastDuration = null;
25709
- // for hls streams which have dvr with a sliding window,
25710
- // the content at the start of the playlist is removed as new
25711
- // content is appended at the end.
25712
- // this means the actual playable start time will increase as the
25713
- // start content is deleted
25714
- // For streams with dvr where the entire recording is kept from the
25715
- // beginning this should stay as 0
25716
- _this._playableRegionStartTime = 0;
25717
- // {local, remote} remote is the time in the video element that should represent 0
25718
- // local is the system time when the 'remote' measurment took place
25719
- _this._localStartTimeCorrelation = null;
25720
- // {local, remote} remote is the time in the video element that should represents the end
25721
- // local is the system time when the 'remote' measurment took place
25722
- _this._localEndTimeCorrelation = null;
25723
- // if content is removed from the beginning then this empty area should
25724
- // be ignored. "playableRegionDuration" excludes the empty area
25725
- _this._playableRegionDuration = 0;
25726
- // #EXT-X-PROGRAM-DATE-TIME
25727
- _this._programDateTime = 0;
25728
- // true when the actual duration is longer than hlsjs's live sync point
25729
- // when this is false playableRegionDuration will be the actual duration
25730
- // when this is true playableRegionDuration will exclude the time after the sync point
25731
- _this._durationExcludesAfterLiveSyncPoint = false;
25732
- // #EXT-X-TARGETDURATION
25733
- _this._segmentTargetDuration = null;
25734
- // #EXT-X-PLAYLIST-TYPE
25735
- _this._playlistType = null;
25736
- _this._recoverAttemptsRemaining = _this.options.hlsRecoverAttempts || 16;
25695
+ _this._setInitialState();
25737
25696
  return _this;
25738
25697
  }
25739
25698
  _createClass(HlsjsPlayback, [{
@@ -25800,9 +25759,9 @@ var HlsjsPlayback = /*#__PURE__*/function (_HTML5Video) {
25800
25759
  get: function get() {
25801
25760
  var actualEndTime = this._playableRegionStartTime + this._playableRegionDuration;
25802
25761
  if (!this._localEndTimeCorrelation) return actualEndTime;
25803
- var corr = this._localEndTimeCorrelation;
25804
- var timePassed = this._now - corr.local;
25805
- var extrapolatedEndTime = (corr.remote + timePassed) / 1000;
25762
+ var correlation = this._localEndTimeCorrelation;
25763
+ var timePassed = this._now - correlation.local;
25764
+ var extrapolatedEndTime = (correlation.remote + timePassed) / 1000;
25806
25765
  return Math.max(actualEndTime - this._extrapolatedWindowDuration, Math.min(extrapolatedEndTime, actualEndTime));
25807
25766
  }
25808
25767
  }, {
@@ -25851,15 +25810,91 @@ var HlsjsPlayback = /*#__PURE__*/function (_HTML5Video) {
25851
25810
  get: function get() {
25852
25811
  return this.options.hlsPlayback && this.options.hlsPlayback.customListeners || [];
25853
25812
  }
25813
+ }, {
25814
+ key: "sourceMedia",
25815
+ get: function get() {
25816
+ return this.options.src;
25817
+ }
25818
+ }, {
25819
+ key: "_setInitialState",
25820
+ value: function _setInitialState() {
25821
+ this._minDvrSize = typeof this.options.hlsMinimumDvrSize === 'undefined' ? 60 : this.options.hlsMinimumDvrSize;
25822
+ // The size of the start time extrapolation window measured as a multiple of segments.
25823
+ // Should be 2 or higher, or 0 to disable. Should only need to be increased above 2 if more than one segment is
25824
+ // removed from the start of the playlist at a time. E.g if the playlist is cached for 10 seconds and new chunks are
25825
+ // added/removed every 5.
25826
+ this._extrapolatedWindowNumSegments = !this.options.playback || typeof this.options.playback.extrapolatedWindowNumSegments === 'undefined' ? 2 : this.options.playback.extrapolatedWindowNumSegments;
25827
+ this._playbackType = Playback.VOD;
25828
+ this._lastTimeUpdate = {
25829
+ current: 0,
25830
+ total: 0
25831
+ };
25832
+ this._lastDuration = null;
25833
+ // for hls streams which have dvr with a sliding window,
25834
+ // the content at the start of the playlist is removed as new
25835
+ // content is appended at the end.
25836
+ // this means the actual playable start time will increase as the
25837
+ // start content is deleted
25838
+ // For streams with dvr where the entire recording is kept from the
25839
+ // beginning this should stay as 0
25840
+ this._playableRegionStartTime = 0;
25841
+ // {local, remote} remote is the time in the video element that should represent 0
25842
+ // local is the system time when the 'remote' measurment took place
25843
+ this._localStartTimeCorrelation = null;
25844
+ // {local, remote} remote is the time in the video element that should represents the end
25845
+ // local is the system time when the 'remote' measurment took place
25846
+ this._localEndTimeCorrelation = null;
25847
+ // if content is removed from the beginning then this empty area should
25848
+ // be ignored. "playableRegionDuration" excludes the empty area
25849
+ this._playableRegionDuration = 0;
25850
+ // #EXT-X-PROGRAM-DATE-TIME
25851
+ this._programDateTime = 0;
25852
+ // true when the actual duration is longer than hlsjs's live sync point
25853
+ // when this is false playableRegionDuration will be the actual duration
25854
+ // when this is true playableRegionDuration will exclude the time after the sync point
25855
+ this._durationExcludesAfterLiveSyncPoint = false;
25856
+ // #EXT-X-TARGETDURATION
25857
+ this._segmentTargetDuration = null;
25858
+ // #EXT-X-PLAYLIST-TYPE
25859
+ this._playlistType = null;
25860
+ this._recoverAttemptsRemaining = this.options.hlsRecoverAttempts || DEFAULT_RECOVER_ATTEMPTS;
25861
+ }
25854
25862
  }, {
25855
25863
  key: "_setup",
25856
25864
  value: function _setup() {
25857
- var _this2 = this;
25865
+ this._destroyHLSInstance();
25866
+ this._createHLSInstance();
25867
+ this._listenHLSEvents();
25868
+ this._attachHLSMedia();
25869
+ }
25870
+ }, {
25871
+ key: "_destroyHLSInstance",
25872
+ value: function _destroyHLSInstance() {
25873
+ if (!this._hls) return;
25858
25874
  this._manifestParsed = false;
25859
25875
  this._ccIsSetup = false;
25860
25876
  this._ccTracksUpdated = false;
25861
- this._hls && this._hls.destroy();
25862
- this._hls = new HLSJS(assign({}, this.options.playback.hlsjsConfig));
25877
+ this._setInitialState();
25878
+ this._hls.destroy();
25879
+ this._hls = null;
25880
+ }
25881
+ }, {
25882
+ key: "_createHLSInstance",
25883
+ value: function _createHLSInstance() {
25884
+ var config = _objectSpread2({}, this.options.playback.hlsjsConfig);
25885
+ this._hls = new HLSJS(config);
25886
+ }
25887
+ }, {
25888
+ key: "_attachHLSMedia",
25889
+ value: function _attachHLSMedia() {
25890
+ if (!this._hls) return;
25891
+ this._hls.attachMedia(this.el);
25892
+ }
25893
+ }, {
25894
+ key: "_listenHLSEvents",
25895
+ value: function _listenHLSEvents() {
25896
+ var _this2 = this;
25897
+ if (!this._hls) return;
25863
25898
  this._hls.once(HLSJS.Events.MEDIA_ATTACHED, function () {
25864
25899
  _this2.options.hlsPlayback.preload && _this2._hls.loadSource(_this2.options.src);
25865
25900
  });
@@ -25894,7 +25929,6 @@ var HlsjsPlayback = /*#__PURE__*/function (_HTML5Video) {
25894
25929
  return _this2._ccTracksUpdated = true;
25895
25930
  });
25896
25931
  this.bindCustomListeners();
25897
- this._hls.attachMedia(this.el);
25898
25932
  }
25899
25933
  }, {
25900
25934
  key: "bindCustomListeners",
@@ -25960,11 +25994,10 @@ var HlsjsPlayback = /*#__PURE__*/function (_HTML5Video) {
25960
25994
  }
25961
25995
 
25962
25996
  // override
25997
+ // this playback manages the src on the video element itself
25963
25998
  }, {
25964
25999
  key: "_setupSrc",
25965
- value: function _setupSrc(srcUrl) {// eslint-disable-line no-unused-vars
25966
- // this playback manages the src on the video element itself
25967
- }
26000
+ value: function _setupSrc(srcUrl) {} // eslint-disable-line no-unused-vars
25968
26001
  }, {
25969
26002
  key: "_startTimeUpdateTimer",
25970
26003
  value: function _startTimeUpdateTimer() {
@@ -25987,6 +26020,7 @@ var HlsjsPlayback = /*#__PURE__*/function (_HTML5Video) {
25987
26020
  value: function getProgramDateTime() {
25988
26021
  return this._programDateTime;
25989
26022
  }
26023
+
25990
26024
  // the duration on the video element itself should not be used
25991
26025
  // as this does not necesarily represent the duration of the stream
25992
26026
  // https://github.com/clappr/clappr/issues/668#issuecomment-157036678
@@ -26015,8 +26049,7 @@ var HlsjsPlayback = /*#__PURE__*/function (_HTML5Video) {
26015
26049
  }, {
26016
26050
  key: "seekPercentage",
26017
26051
  value: function seekPercentage(percentage) {
26018
- var seekTo = this._duration;
26019
- if (percentage > 0) seekTo = this._duration * (percentage / 100);
26052
+ var seekTo = percentage > 0 ? this._duration * (percentage / 100) : this._duration;
26020
26053
  this.seek(seekTo);
26021
26054
  }
26022
26055
  }, {
@@ -26191,6 +26224,13 @@ var HlsjsPlayback = /*#__PURE__*/function (_HTML5Video) {
26191
26224
  };
26192
26225
  this.trigger(Events.PLAYBACK_PROGRESS, progress, buffered);
26193
26226
  }
26227
+ }, {
26228
+ key: "load",
26229
+ value: function load(url) {
26230
+ this._stopTimeUpdateTimer();
26231
+ this.options.src = url;
26232
+ this._setup();
26233
+ }
26194
26234
  }, {
26195
26235
  key: "play",
26196
26236
  value: function play() {
@@ -26210,20 +26250,14 @@ var HlsjsPlayback = /*#__PURE__*/function (_HTML5Video) {
26210
26250
  key: "stop",
26211
26251
  value: function stop() {
26212
26252
  this._stopTimeUpdateTimer();
26213
- if (this._hls) {
26214
- _get(_getPrototypeOf(HlsjsPlayback.prototype), "stop", this).call(this);
26215
- this._hls.destroy();
26216
- delete this._hls;
26217
- }
26253
+ if (this._hls) _get(_getPrototypeOf(HlsjsPlayback.prototype), "stop", this).call(this);
26254
+ this._destroyHLSInstance();
26218
26255
  }
26219
26256
  }, {
26220
26257
  key: "destroy",
26221
26258
  value: function destroy() {
26222
26259
  this._stopTimeUpdateTimer();
26223
- if (this._hls) {
26224
- this._hls.destroy();
26225
- delete this._hls;
26226
- }
26260
+ this._destroyHLSInstance();
26227
26261
  _get(_getPrototypeOf(HlsjsPlayback.prototype), "destroy", this).call(this);
26228
26262
  }
26229
26263
  }, {
@@ -26231,7 +26265,6 @@ var HlsjsPlayback = /*#__PURE__*/function (_HTML5Video) {
26231
26265
  value: function _updatePlaybackType(evt, data) {
26232
26266
  this._playbackType = data.details.live ? Playback.LIVE : Playback.VOD;
26233
26267
  this._onLevelUpdated(evt, data);
26234
-
26235
26268
  // Live stream subtitle tracks detection hack (may not immediately available)
26236
26269
  if (this._ccTracksUpdated && this._playbackType === Playback.LIVE && this.hasClosedCaptionsTracks) this._onSubtitleLoaded();
26237
26270
  }
@@ -26258,7 +26291,6 @@ var HlsjsPlayback = /*#__PURE__*/function (_HTML5Video) {
26258
26291
  var previousPlayableRegionStartTime = this._playableRegionStartTime;
26259
26292
  var previousPlayableRegionDuration = this._playableRegionDuration;
26260
26293
  if (fragments.length === 0) return;
26261
-
26262
26294
  // #EXT-X-PROGRAM-DATE-TIME
26263
26295
  if (fragments[0].rawProgramDateTime) this._programDateTime = fragments[0].rawProgramDateTime;
26264
26296
  if (this._playableRegionStartTime !== fragments[0].start) {
@@ -26318,7 +26350,6 @@ var HlsjsPlayback = /*#__PURE__*/function (_HTML5Video) {
26318
26350
  durationChanged = true;
26319
26351
  this._playableRegionDuration = newDuration;
26320
26352
  }
26321
-
26322
26353
  // Note the end time is not the playableRegionDuration
26323
26354
  // The end time will always increase even if content is removed from the beginning
26324
26355
  var endTime = fragments[0].start + newDuration;
@@ -197,9 +197,9 @@
197
197
  }
198
198
 
199
199
  var now = core.Utils.now,
200
- assign = core.Utils.assign,
201
200
  listContainsIgnoreCase = core.Utils.listContainsIgnoreCase;
202
201
  var AUTO = -1;
202
+ var DEFAULT_RECOVER_ATTEMPTS = 16;
203
203
  core.Events.register('PLAYBACK_FRAGMENT_CHANGED');
204
204
  core.Events.register('PLAYBACK_FRAGMENT_PARSING_METADATA');
205
205
  var HlsjsPlayback = /*#__PURE__*/function (_HTML5Video) {
@@ -212,49 +212,8 @@
212
212
  args[_key] = arguments[_key];
213
213
  }
214
214
  _this = _super.call.apply(_super, [this].concat(args));
215
- // backwards compatibility (TODO: remove on 0.3.0)
216
- _this.options.playback = _objectSpread2(_objectSpread2({}, _this.options), _this.options.playback);
217
215
  _this.options.hlsPlayback = _objectSpread2(_objectSpread2({}, _this.defaultOptions), _this.options.hlsPlayback);
218
- _this._minDvrSize = typeof _this.options.hlsMinimumDvrSize === 'undefined' ? 60 : _this.options.hlsMinimumDvrSize;
219
- // The size of the start time extrapolation window measured as a multiple of segments.
220
- // Should be 2 or higher, or 0 to disable. Should only need to be increased above 2 if more than one segment is
221
- // removed from the start of the playlist at a time. E.g if the playlist is cached for 10 seconds and new chunks are
222
- // added/removed every 5.
223
- _this._extrapolatedWindowNumSegments = !_this.options.playback || typeof _this.options.playback.extrapolatedWindowNumSegments === 'undefined' ? 2 : _this.options.playback.extrapolatedWindowNumSegments;
224
- _this._playbackType = core.Playback.VOD;
225
- _this._lastTimeUpdate = {
226
- current: 0,
227
- total: 0
228
- };
229
- _this._lastDuration = null;
230
- // for hls streams which have dvr with a sliding window,
231
- // the content at the start of the playlist is removed as new
232
- // content is appended at the end.
233
- // this means the actual playable start time will increase as the
234
- // start content is deleted
235
- // For streams with dvr where the entire recording is kept from the
236
- // beginning this should stay as 0
237
- _this._playableRegionStartTime = 0;
238
- // {local, remote} remote is the time in the video element that should represent 0
239
- // local is the system time when the 'remote' measurment took place
240
- _this._localStartTimeCorrelation = null;
241
- // {local, remote} remote is the time in the video element that should represents the end
242
- // local is the system time when the 'remote' measurment took place
243
- _this._localEndTimeCorrelation = null;
244
- // if content is removed from the beginning then this empty area should
245
- // be ignored. "playableRegionDuration" excludes the empty area
246
- _this._playableRegionDuration = 0;
247
- // #EXT-X-PROGRAM-DATE-TIME
248
- _this._programDateTime = 0;
249
- // true when the actual duration is longer than hlsjs's live sync point
250
- // when this is false playableRegionDuration will be the actual duration
251
- // when this is true playableRegionDuration will exclude the time after the sync point
252
- _this._durationExcludesAfterLiveSyncPoint = false;
253
- // #EXT-X-TARGETDURATION
254
- _this._segmentTargetDuration = null;
255
- // #EXT-X-PLAYLIST-TYPE
256
- _this._playlistType = null;
257
- _this._recoverAttemptsRemaining = _this.options.hlsRecoverAttempts || 16;
216
+ _this._setInitialState();
258
217
  return _this;
259
218
  }
260
219
  _createClass(HlsjsPlayback, [{
@@ -321,9 +280,9 @@
321
280
  get: function get() {
322
281
  var actualEndTime = this._playableRegionStartTime + this._playableRegionDuration;
323
282
  if (!this._localEndTimeCorrelation) return actualEndTime;
324
- var corr = this._localEndTimeCorrelation;
325
- var timePassed = this._now - corr.local;
326
- var extrapolatedEndTime = (corr.remote + timePassed) / 1000;
283
+ var correlation = this._localEndTimeCorrelation;
284
+ var timePassed = this._now - correlation.local;
285
+ var extrapolatedEndTime = (correlation.remote + timePassed) / 1000;
327
286
  return Math.max(actualEndTime - this._extrapolatedWindowDuration, Math.min(extrapolatedEndTime, actualEndTime));
328
287
  }
329
288
  }, {
@@ -372,15 +331,91 @@
372
331
  get: function get() {
373
332
  return this.options.hlsPlayback && this.options.hlsPlayback.customListeners || [];
374
333
  }
334
+ }, {
335
+ key: "sourceMedia",
336
+ get: function get() {
337
+ return this.options.src;
338
+ }
339
+ }, {
340
+ key: "_setInitialState",
341
+ value: function _setInitialState() {
342
+ this._minDvrSize = typeof this.options.hlsMinimumDvrSize === 'undefined' ? 60 : this.options.hlsMinimumDvrSize;
343
+ // The size of the start time extrapolation window measured as a multiple of segments.
344
+ // Should be 2 or higher, or 0 to disable. Should only need to be increased above 2 if more than one segment is
345
+ // removed from the start of the playlist at a time. E.g if the playlist is cached for 10 seconds and new chunks are
346
+ // added/removed every 5.
347
+ this._extrapolatedWindowNumSegments = !this.options.playback || typeof this.options.playback.extrapolatedWindowNumSegments === 'undefined' ? 2 : this.options.playback.extrapolatedWindowNumSegments;
348
+ this._playbackType = core.Playback.VOD;
349
+ this._lastTimeUpdate = {
350
+ current: 0,
351
+ total: 0
352
+ };
353
+ this._lastDuration = null;
354
+ // for hls streams which have dvr with a sliding window,
355
+ // the content at the start of the playlist is removed as new
356
+ // content is appended at the end.
357
+ // this means the actual playable start time will increase as the
358
+ // start content is deleted
359
+ // For streams with dvr where the entire recording is kept from the
360
+ // beginning this should stay as 0
361
+ this._playableRegionStartTime = 0;
362
+ // {local, remote} remote is the time in the video element that should represent 0
363
+ // local is the system time when the 'remote' measurment took place
364
+ this._localStartTimeCorrelation = null;
365
+ // {local, remote} remote is the time in the video element that should represents the end
366
+ // local is the system time when the 'remote' measurment took place
367
+ this._localEndTimeCorrelation = null;
368
+ // if content is removed from the beginning then this empty area should
369
+ // be ignored. "playableRegionDuration" excludes the empty area
370
+ this._playableRegionDuration = 0;
371
+ // #EXT-X-PROGRAM-DATE-TIME
372
+ this._programDateTime = 0;
373
+ // true when the actual duration is longer than hlsjs's live sync point
374
+ // when this is false playableRegionDuration will be the actual duration
375
+ // when this is true playableRegionDuration will exclude the time after the sync point
376
+ this._durationExcludesAfterLiveSyncPoint = false;
377
+ // #EXT-X-TARGETDURATION
378
+ this._segmentTargetDuration = null;
379
+ // #EXT-X-PLAYLIST-TYPE
380
+ this._playlistType = null;
381
+ this._recoverAttemptsRemaining = this.options.hlsRecoverAttempts || DEFAULT_RECOVER_ATTEMPTS;
382
+ }
375
383
  }, {
376
384
  key: "_setup",
377
385
  value: function _setup() {
378
- var _this2 = this;
386
+ this._destroyHLSInstance();
387
+ this._createHLSInstance();
388
+ this._listenHLSEvents();
389
+ this._attachHLSMedia();
390
+ }
391
+ }, {
392
+ key: "_destroyHLSInstance",
393
+ value: function _destroyHLSInstance() {
394
+ if (!this._hls) return;
379
395
  this._manifestParsed = false;
380
396
  this._ccIsSetup = false;
381
397
  this._ccTracksUpdated = false;
382
- this._hls && this._hls.destroy();
383
- this._hls = new HLSJS__default["default"](assign({}, this.options.playback.hlsjsConfig));
398
+ this._setInitialState();
399
+ this._hls.destroy();
400
+ this._hls = null;
401
+ }
402
+ }, {
403
+ key: "_createHLSInstance",
404
+ value: function _createHLSInstance() {
405
+ var config = _objectSpread2({}, this.options.playback.hlsjsConfig);
406
+ this._hls = new HLSJS__default["default"](config);
407
+ }
408
+ }, {
409
+ key: "_attachHLSMedia",
410
+ value: function _attachHLSMedia() {
411
+ if (!this._hls) return;
412
+ this._hls.attachMedia(this.el);
413
+ }
414
+ }, {
415
+ key: "_listenHLSEvents",
416
+ value: function _listenHLSEvents() {
417
+ var _this2 = this;
418
+ if (!this._hls) return;
384
419
  this._hls.once(HLSJS__default["default"].Events.MEDIA_ATTACHED, function () {
385
420
  _this2.options.hlsPlayback.preload && _this2._hls.loadSource(_this2.options.src);
386
421
  });
@@ -415,7 +450,6 @@
415
450
  return _this2._ccTracksUpdated = true;
416
451
  });
417
452
  this.bindCustomListeners();
418
- this._hls.attachMedia(this.el);
419
453
  }
420
454
  }, {
421
455
  key: "bindCustomListeners",
@@ -481,11 +515,10 @@
481
515
  }
482
516
 
483
517
  // override
518
+ // this playback manages the src on the video element itself
484
519
  }, {
485
520
  key: "_setupSrc",
486
- value: function _setupSrc(srcUrl) {// eslint-disable-line no-unused-vars
487
- // this playback manages the src on the video element itself
488
- }
521
+ value: function _setupSrc(srcUrl) {} // eslint-disable-line no-unused-vars
489
522
  }, {
490
523
  key: "_startTimeUpdateTimer",
491
524
  value: function _startTimeUpdateTimer() {
@@ -508,6 +541,7 @@
508
541
  value: function getProgramDateTime() {
509
542
  return this._programDateTime;
510
543
  }
544
+
511
545
  // the duration on the video element itself should not be used
512
546
  // as this does not necesarily represent the duration of the stream
513
547
  // https://github.com/clappr/clappr/issues/668#issuecomment-157036678
@@ -536,8 +570,7 @@
536
570
  }, {
537
571
  key: "seekPercentage",
538
572
  value: function seekPercentage(percentage) {
539
- var seekTo = this._duration;
540
- if (percentage > 0) seekTo = this._duration * (percentage / 100);
573
+ var seekTo = percentage > 0 ? this._duration * (percentage / 100) : this._duration;
541
574
  this.seek(seekTo);
542
575
  }
543
576
  }, {
@@ -712,6 +745,13 @@
712
745
  };
713
746
  this.trigger(core.Events.PLAYBACK_PROGRESS, progress, buffered);
714
747
  }
748
+ }, {
749
+ key: "load",
750
+ value: function load(url) {
751
+ this._stopTimeUpdateTimer();
752
+ this.options.src = url;
753
+ this._setup();
754
+ }
715
755
  }, {
716
756
  key: "play",
717
757
  value: function play() {
@@ -731,20 +771,14 @@
731
771
  key: "stop",
732
772
  value: function stop() {
733
773
  this._stopTimeUpdateTimer();
734
- if (this._hls) {
735
- _get(_getPrototypeOf(HlsjsPlayback.prototype), "stop", this).call(this);
736
- this._hls.destroy();
737
- delete this._hls;
738
- }
774
+ if (this._hls) _get(_getPrototypeOf(HlsjsPlayback.prototype), "stop", this).call(this);
775
+ this._destroyHLSInstance();
739
776
  }
740
777
  }, {
741
778
  key: "destroy",
742
779
  value: function destroy() {
743
780
  this._stopTimeUpdateTimer();
744
- if (this._hls) {
745
- this._hls.destroy();
746
- delete this._hls;
747
- }
781
+ this._destroyHLSInstance();
748
782
  _get(_getPrototypeOf(HlsjsPlayback.prototype), "destroy", this).call(this);
749
783
  }
750
784
  }, {
@@ -752,7 +786,6 @@
752
786
  value: function _updatePlaybackType(evt, data) {
753
787
  this._playbackType = data.details.live ? core.Playback.LIVE : core.Playback.VOD;
754
788
  this._onLevelUpdated(evt, data);
755
-
756
789
  // Live stream subtitle tracks detection hack (may not immediately available)
757
790
  if (this._ccTracksUpdated && this._playbackType === core.Playback.LIVE && this.hasClosedCaptionsTracks) this._onSubtitleLoaded();
758
791
  }
@@ -779,7 +812,6 @@
779
812
  var previousPlayableRegionStartTime = this._playableRegionStartTime;
780
813
  var previousPlayableRegionDuration = this._playableRegionDuration;
781
814
  if (fragments.length === 0) return;
782
-
783
815
  // #EXT-X-PROGRAM-DATE-TIME
784
816
  if (fragments[0].rawProgramDateTime) this._programDateTime = fragments[0].rawProgramDateTime;
785
817
  if (this._playableRegionStartTime !== fragments[0].start) {
@@ -839,7 +871,6 @@
839
871
  durationChanged = true;
840
872
  this._playableRegionDuration = newDuration;
841
873
  }
842
-
843
874
  // Note the end time is not the playableRegionDuration
844
875
  // The end time will always increase even if content is removed from the beginning
845
876
  var endTime = fragments[0].start + newDuration;
@@ -1,2 +1,2 @@
1
- var HlsjsPlayback=function(t,e){"use strict";function r(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var i=r(Hls);function n(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);e&&(i=i.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,i)}return r}function a(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?n(Object(r),!0).forEach((function(e){l(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):n(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}function o(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function s(t,e){for(var r=0;r<e.length;r++){var i=e[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,v(i.key),i)}}function l(t,e,r){return(e=v(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function u(t){return u=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},u(t)}function c(t,e){return c=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},c(t,e)}function h(t,e){if(e&&("object"==typeof e||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}function _(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var r,i=u(t);if(e){var n=u(this).constructor;r=Reflect.construct(i,arguments,n)}else r=i.apply(this,arguments);return h(this,r)}}function p(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=u(t)););return t}function d(){return d="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(t,e,r){var i=p(t,e);if(i){var n=Object.getOwnPropertyDescriptor(i,e);return n.get?n.get.call(arguments.length<3?t:r):n.value}},d.apply(this,arguments)}function f(t){return function(t){if(Array.isArray(t))return y(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||function(t,e){if(!t)return;if("string"==typeof t)return y(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);"Object"===r&&t.constructor&&(r=t.constructor.name);if("Map"===r||"Set"===r)return Array.from(t);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return y(t,e)}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function y(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,i=new Array(e);r<e;r++)i[r]=t[r];return i}function v(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var i=r.call(t,e||"default");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}var g=t.Utils.now,m=t.Utils.assign,E=t.Utils.listContainsIgnoreCase;t.Events.register("PLAYBACK_FRAGMENT_CHANGED"),t.Events.register("PLAYBACK_FRAGMENT_PARSING_METADATA");var T=function(e){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&c(t,e)}(p,e);var r,n,l,h=_(p);function p(){var e;o(this,p);for(var r=arguments.length,i=new Array(r),n=0;n<r;n++)i[n]=arguments[n];return(e=h.call.apply(h,[this].concat(i))).options.playback=a(a({},e.options),e.options.playback),e.options.hlsPlayback=a(a({},e.defaultOptions),e.options.hlsPlayback),e._minDvrSize=void 0===e.options.hlsMinimumDvrSize?60:e.options.hlsMinimumDvrSize,e._extrapolatedWindowNumSegments=e.options.playback&&void 0!==e.options.playback.extrapolatedWindowNumSegments?e.options.playback.extrapolatedWindowNumSegments:2,e._playbackType=t.Playback.VOD,e._lastTimeUpdate={current:0,total:0},e._lastDuration=null,e._playableRegionStartTime=0,e._localStartTimeCorrelation=null,e._localEndTimeCorrelation=null,e._playableRegionDuration=0,e._programDateTime=0,e._durationExcludesAfterLiveSyncPoint=!1,e._segmentTargetDuration=null,e._playlistType=null,e._recoverAttemptsRemaining=e.options.hlsRecoverAttempts||16,e}return r=p,l=[{key:"HLSJS",get:function(){return i.default}}],(n=[{key:"name",get:function(){return"hls"}},{key:"supportedVersion",get:function(){return{min:"0.4.27"}}},{key:"levels",get:function(){return this._levels||[]}},{key:"currentLevel",get:function(){return null===this._currentLevel||void 0===this._currentLevel?-1:this._currentLevel},set:function(e){this._currentLevel=e,this.trigger(t.Events.PLAYBACK_LEVEL_SWITCH_START),this.options.playback.hlsUseNextLevel?this._hls.nextLevel=this._currentLevel:this._hls.currentLevel=this._currentLevel}},{key:"isReady",get:function(){return this._isReadyState}},{key:"_startTime",get:function(){return this._playbackType===t.Playback.LIVE&&"EVENT"!==this._playlistType?this._extrapolatedStartTime:this._playableRegionStartTime}},{key:"_now",get:function(){return g()}},{key:"_extrapolatedStartTime",get:function(){if(!this._localStartTimeCorrelation)return this._playableRegionStartTime;var t=this._localStartTimeCorrelation,e=this._now-t.local,r=(t.remote+e)/1e3;return Math.min(r,this._playableRegionStartTime+this._extrapolatedWindowDuration)}},{key:"_extrapolatedEndTime",get:function(){var t=this._playableRegionStartTime+this._playableRegionDuration;if(!this._localEndTimeCorrelation)return t;var e=this._localEndTimeCorrelation,r=this._now-e.local,i=(e.remote+r)/1e3;return Math.max(t-this._extrapolatedWindowDuration,Math.min(i,t))}},{key:"_duration",get:function(){return this._extrapolatedEndTime-this._startTime}},{key:"_extrapolatedWindowDuration",get:function(){return null===this._segmentTargetDuration?0:this._extrapolatedWindowNumSegments*this._segmentTargetDuration}},{key:"bandwidthEstimate",get:function(){return this._hls&&this._hls.bandwidthEstimate}},{key:"defaultOptions",get:function(){return{preload:!0}}},{key:"customListeners",get:function(){return this.options.hlsPlayback&&this.options.hlsPlayback.customListeners||[]}},{key:"_setup",value:function(){var t=this;this._manifestParsed=!1,this._ccIsSetup=!1,this._ccTracksUpdated=!1,this._hls&&this._hls.destroy(),this._hls=new i.default(m({},this.options.playback.hlsjsConfig)),this._hls.once(i.default.Events.MEDIA_ATTACHED,(function(){t.options.hlsPlayback.preload&&t._hls.loadSource(t.options.src)})),this._hls.on(i.default.Events.MANIFEST_PARSED,(function(){return t._manifestParsed=!0})),this._hls.on(i.default.Events.LEVEL_LOADED,(function(e,r){return t._updatePlaybackType(e,r)})),this._hls.on(i.default.Events.LEVEL_UPDATED,(function(e,r){return t._onLevelUpdated(e,r)})),this._hls.on(i.default.Events.LEVEL_SWITCHING,(function(e,r){return t._onLevelSwitch(e,r)})),this._hls.on(i.default.Events.FRAG_CHANGED,(function(e,r){return t._onFragmentChanged(e,r)})),this._hls.on(i.default.Events.FRAG_LOADED,(function(e,r){return t._onFragmentLoaded(e,r)})),this._hls.on(i.default.Events.FRAG_PARSING_METADATA,(function(e,r){return t._onFragmentParsingMetadata(e,r)})),this._hls.on(i.default.Events.ERROR,(function(e,r){return t._onHLSJSError(e,r)})),this._hls.on(i.default.Events.SUBTITLE_TRACK_LOADED,(function(e,r){return t._onSubtitleLoaded(e,r)})),this._hls.on(i.default.Events.SUBTITLE_TRACKS_UPDATED,(function(){return t._ccTracksUpdated=!0})),this.bindCustomListeners(),this._hls.attachMedia(this.el)}},{key:"bindCustomListeners",value:function(){var t=this;this.customListeners.forEach((function(e){var r=e.eventName,i=e.once?"once":"on";r&&t._hls["".concat(i)](r,e.callback)}))}},{key:"unbindCustomListeners",value:function(){var t=this;this.customListeners.forEach((function(e){var r=e.eventName;r&&t._hls.off(r,e.callback)}))}},{key:"_onFragmentParsingMetadata",value:function(e,r){this.trigger(t.Events.Custom.PLAYBACK_FRAGMENT_PARSING_METADATA,{evt:e,data:r})}},{key:"render",value:function(){return this._ready(),d(u(p.prototype),"render",this).call(this)}},{key:"_ready",value:function(){this._isReadyState||(!this._hls&&this._setup(),this._isReadyState=!0,this.trigger(t.Events.PLAYBACK_READY,this.name))}},{key:"_recover",value:function(e,r,i){if(this._recoveredDecodingError)if(this._recoveredAudioCodecError){t.Log.error("hlsjs: failed to recover",{evt:e,data:r}),i.level=t.PlayerError.Levels.FATAL;var n=this.createError(i);this.trigger(t.Events.PLAYBACK_ERROR,n),this.stop()}else this._recoveredAudioCodecError=!0,this._hls.swapAudioCodec(),this._hls.recoverMediaError();else this._recoveredDecodingError=!0,this._hls.recoverMediaError()}},{key:"_setupSrc",value:function(t){}},{key:"_startTimeUpdateTimer",value:function(){var t=this;this._timeUpdateTimer||(this._timeUpdateTimer=setInterval((function(){t._onDurationChange(),t._onTimeUpdate()}),100))}},{key:"_stopTimeUpdateTimer",value:function(){this._timeUpdateTimer&&(clearInterval(this._timeUpdateTimer),this._timeUpdateTimer=null)}},{key:"getProgramDateTime",value:function(){return this._programDateTime}},{key:"getDuration",value:function(){return this._duration}},{key:"getCurrentTime",value:function(){return Math.max(0,this.el.currentTime-this._startTime)}},{key:"getStartTimeOffset",value:function(){return this._startTime}},{key:"seekPercentage",value:function(t){var e=this._duration;t>0&&(e=this._duration*(t/100)),this.seek(e)}},{key:"seek",value:function(e){e<0&&(t.Log.warn("Attempt to seek to a negative time. Resetting to live point. Use seekToLivePoint() to seek to the live point."),e=this.getDuration()),this.dvrEnabled&&this._updateDvr(e<this.getDuration()-3),e+=this._startTime,this.el.currentTime=e}},{key:"seekToLivePoint",value:function(){this.seek(this.getDuration())}},{key:"_updateDvr",value:function(e){this.trigger(t.Events.PLAYBACK_DVR,e),this.trigger(t.Events.PLAYBACK_STATS_ADD,{dvr:e})}},{key:"_updateSettings",value:function(){this._playbackType===t.Playback.VOD?this.settings.left=["playpause","position","duration"]:this.dvrEnabled?this.settings.left=["playpause"]:this.settings.left=["playstop"],this.settings.seekEnabled=this.isSeekEnabled(),this.trigger(t.Events.PLAYBACK_SETTINGSUPDATE)}},{key:"_onHLSJSError",value:function(e,r){var n,a={code:"".concat(r.type,"_").concat(r.details),description:"".concat(this.name," error: type: ").concat(r.type,", details: ").concat(r.details),raw:r};if(r.response&&(a.description+=", response: ".concat(JSON.stringify(r.response))),r.fatal)if(this._recoverAttemptsRemaining>0)switch(this._recoverAttemptsRemaining-=1,r.type){case i.default.ErrorTypes.NETWORK_ERROR:switch(r.details){case i.default.ErrorDetails.MANIFEST_LOAD_ERROR:case i.default.ErrorDetails.MANIFEST_LOAD_TIMEOUT:case i.default.ErrorDetails.MANIFEST_PARSING_ERROR:case i.default.ErrorDetails.LEVEL_LOAD_ERROR:case i.default.ErrorDetails.LEVEL_LOAD_TIMEOUT:t.Log.error("hlsjs: unrecoverable network fatal error.",{evt:e,data:r}),n=this.createError(a),this.trigger(t.Events.PLAYBACK_ERROR,n),this.stop();break;default:t.Log.warn("hlsjs: trying to recover from network error.",{evt:e,data:r}),a.level=t.PlayerError.Levels.WARN,this._hls.startLoad()}break;case i.default.ErrorTypes.MEDIA_ERROR:t.Log.warn("hlsjs: trying to recover from media error.",{evt:e,data:r}),a.level=t.PlayerError.Levels.WARN,this._recover(e,r,a);break;default:t.Log.error("hlsjs: could not recover from error.",{evt:e,data:r}),n=this.createError(a),this.trigger(t.Events.PLAYBACK_ERROR,n),this.stop()}else t.Log.error("hlsjs: could not recover from error after maximum number of attempts.",{evt:e,data:r}),n=this.createError(a),this.trigger(t.Events.PLAYBACK_ERROR,n),this.stop();else{if(this.options.playback.triggerFatalErrorOnResourceDenied&&this._keyIsDenied(r))return t.Log.error("hlsjs: could not load decrypt key.",{evt:e,data:r}),n=this.createError(a),this.trigger(t.Events.PLAYBACK_ERROR,n),void this.stop();a.level=t.PlayerError.Levels.WARN,t.Log.warn("hlsjs: non-fatal error occurred",{evt:e,data:r})}}},{key:"_keyIsDenied",value:function(t){return t.type===i.default.ErrorTypes.NETWORK_ERROR&&t.details===i.default.ErrorDetails.KEY_LOAD_ERROR&&t.response&&t.response.code>=400}},{key:"_onTimeUpdate",value:function(){var e={current:this.getCurrentTime(),total:this.getDuration(),firstFragDateTime:this.getProgramDateTime()};this._lastTimeUpdate&&e.current===this._lastTimeUpdate.current&&e.total===this._lastTimeUpdate.total||(this._lastTimeUpdate=e,this.trigger(t.Events.PLAYBACK_TIMEUPDATE,e,this.name))}},{key:"_onDurationChange",value:function(){var t=this.getDuration();this._lastDuration!==t&&(this._lastDuration=t,d(u(p.prototype),"_onDurationChange",this).call(this))}},{key:"_onProgress",value:function(){if(this.el.buffered.length){for(var e=[],r=0,i=0;i<this.el.buffered.length;i++)e=[].concat(f(e),[{start:Math.max(0,this.el.buffered.start(i)-this._playableRegionStartTime),end:Math.max(0,this.el.buffered.end(i)-this._playableRegionStartTime)}]),this.el.currentTime>=e[i].start&&this.el.currentTime<=e[i].end&&(r=i);var n={start:e[r].start,current:e[r].end,total:this.getDuration()};this.trigger(t.Events.PLAYBACK_PROGRESS,n,e)}}},{key:"play",value:function(){!this._hls&&this._setup(),!this._manifestParsed&&!this.options.hlsPlayback.preload&&this._hls.loadSource(this.options.src),d(u(p.prototype),"play",this).call(this),this._startTimeUpdateTimer()}},{key:"pause",value:function(){this._hls&&(this.el.pause(),this.dvrEnabled&&this._updateDvr(!0))}},{key:"stop",value:function(){this._stopTimeUpdateTimer(),this._hls&&(d(u(p.prototype),"stop",this).call(this),this._hls.destroy(),delete this._hls)}},{key:"destroy",value:function(){this._stopTimeUpdateTimer(),this._hls&&(this._hls.destroy(),delete this._hls),d(u(p.prototype),"destroy",this).call(this)}},{key:"_updatePlaybackType",value:function(e,r){this._playbackType=r.details.live?t.Playback.LIVE:t.Playback.VOD,this._onLevelUpdated(e,r),this._ccTracksUpdated&&this._playbackType===t.Playback.LIVE&&this.hasClosedCaptionsTracks&&this._onSubtitleLoaded()}},{key:"_fillLevels",value:function(){this._levels=this._hls.levels.map((function(t,e){return{id:e,level:t,label:"".concat(t.bitrate/1e3,"Kbps")}})),this.trigger(t.Events.PLAYBACK_LEVELS_AVAILABLE,this._levels)}},{key:"_onLevelUpdated",value:function(e,r){this._segmentTargetDuration=r.details.targetduration,this._playlistType=r.details.type||null;var n=!1,a=!1,o=r.details.fragments,s=this._playableRegionStartTime,l=this._playableRegionDuration;if(0!==o.length){if(o[0].rawProgramDateTime&&(this._programDateTime=o[0].rawProgramDateTime),this._playableRegionStartTime!==o[0].start&&(n=!0,this._playableRegionStartTime=o[0].start),n)if(this._localStartTimeCorrelation){var u=this._localStartTimeCorrelation,c=this._now-u.local,h=(u.remote+c)/1e3;h<o[0].start?this._localStartTimeCorrelation={local:this._now,remote:1e3*o[0].start}:h>s+this._extrapolatedWindowDuration&&(this._localStartTimeCorrelation={local:this._now,remote:1e3*Math.max(o[0].start,s+this._extrapolatedWindowDuration)})}else this._localStartTimeCorrelation={local:this._now,remote:1e3*(o[0].start+this._extrapolatedWindowDuration/2)};var _=r.details.totalduration;if(this._playbackType===t.Playback.LIVE){var p=r.details.targetduration*((this.options.playback.hlsjsConfig||{}).liveSyncDurationCount||i.default.DefaultConfig.liveSyncDurationCount);p<=_?(_-=p,this._durationExcludesAfterLiveSyncPoint=!0):this._durationExcludesAfterLiveSyncPoint=!1}_!==this._playableRegionDuration&&(a=!0,this._playableRegionDuration=_);var d=o[0].start+_,f=s+l;if(d!==f)if(this._localEndTimeCorrelation){var y=this._localEndTimeCorrelation,v=this._now-y.local,g=(y.remote+v)/1e3;g>d?this._localEndTimeCorrelation={local:this._now,remote:1e3*d}:g<d-this._extrapolatedWindowDuration?this._localEndTimeCorrelation={local:this._now,remote:1e3*(d-this._extrapolatedWindowDuration)}:g>f&&(this._localEndTimeCorrelation={local:this._now,remote:1e3*f})}else this._localEndTimeCorrelation={local:this._now,remote:1e3*d};a&&this._onDurationChange(),n&&this._onProgress()}}},{key:"_onFragmentChanged",value:function(e,r){this.trigger(t.Events.Custom.PLAYBACK_FRAGMENT_CHANGED,r)}},{key:"_onFragmentLoaded",value:function(e,r){this.trigger(t.Events.PLAYBACK_FRAGMENT_LOADED,r)}},{key:"_onSubtitleLoaded",value:function(){if(!this._ccIsSetup){this.trigger(t.Events.PLAYBACK_SUBTITLE_AVAILABLE);var e=this._playbackType===t.Playback.LIVE?-1:this.closedCaptionsTrackId;this.closedCaptionsTrackId=e,this._ccIsSetup=!0}}},{key:"_onLevelSwitch",value:function(e,r){this.levels.length||this._fillLevels(),this.trigger(t.Events.PLAYBACK_LEVEL_SWITCH_END),this.trigger(t.Events.PLAYBACK_LEVEL_SWITCH,r);var i=this._hls.levels[r.level];i&&(this.highDefinition=i.height>=720||i.bitrate/1e3>=2e3,this.trigger(t.Events.PLAYBACK_HIGHDEFINITIONUPDATE,this.highDefinition),this.trigger(t.Events.PLAYBACK_BITRATE,{height:i.height,width:i.width,bandwidth:i.bitrate,bitrate:i.bitrate,level:r.level}))}},{key:"dvrEnabled",get:function(){return this._durationExcludesAfterLiveSyncPoint&&this._duration>=this._minDvrSize&&this.getPlaybackType()===t.Playback.LIVE}},{key:"getPlaybackType",value:function(){return this._playbackType}},{key:"isSeekEnabled",value:function(){return this._playbackType===t.Playback.VOD||this.dvrEnabled}}])&&s(r.prototype,n),l&&s(r,l),Object.defineProperty(r,"prototype",{writable:!1}),p}(t.HTML5Video);return T.canPlay=function(t,e){var r=t.split("?")[0].match(/.*\.(.*)$/)||[],n=r.length>1&&"m3u8"===r[1].toLowerCase()||E(e,["application/vnd.apple.mpegurl","application/x-mpegURL"]);return!(!i.default.isSupported()||!n)},T}(Clappr);
1
+ var HlsjsPlayback=function(t,e){"use strict";function r(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var i=r(Hls);function n(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);e&&(i=i.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,i)}return r}function a(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?n(Object(r),!0).forEach((function(e){l(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):n(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}function o(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function s(t,e){for(var r=0;r<e.length;r++){var i=e[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,v(i.key),i)}}function l(t,e,r){return(e=v(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function u(t){return u=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},u(t)}function c(t,e){return c=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},c(t,e)}function h(t,e){if(e&&("object"==typeof e||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}function _(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var r,i=u(t);if(e){var n=u(this).constructor;r=Reflect.construct(i,arguments,n)}else r=i.apply(this,arguments);return h(this,r)}}function d(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=u(t)););return t}function p(){return p="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(t,e,r){var i=d(t,e);if(i){var n=Object.getOwnPropertyDescriptor(i,e);return n.get?n.get.call(arguments.length<3?t:r):n.value}},p.apply(this,arguments)}function f(t){return function(t){if(Array.isArray(t))return y(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||function(t,e){if(!t)return;if("string"==typeof t)return y(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);"Object"===r&&t.constructor&&(r=t.constructor.name);if("Map"===r||"Set"===r)return Array.from(t);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return y(t,e)}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function y(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,i=new Array(e);r<e;r++)i[r]=t[r];return i}function v(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var i=r.call(t,e||"default");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}var m=t.Utils.now,g=t.Utils.listContainsIgnoreCase;t.Events.register("PLAYBACK_FRAGMENT_CHANGED"),t.Events.register("PLAYBACK_FRAGMENT_PARSING_METADATA");var E=function(e){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&c(t,e)}(d,e);var r,n,l,h=_(d);function d(){var t;o(this,d);for(var e=arguments.length,r=new Array(e),i=0;i<e;i++)r[i]=arguments[i];return(t=h.call.apply(h,[this].concat(r))).options.hlsPlayback=a(a({},t.defaultOptions),t.options.hlsPlayback),t._setInitialState(),t}return r=d,l=[{key:"HLSJS",get:function(){return i.default}}],(n=[{key:"name",get:function(){return"hls"}},{key:"supportedVersion",get:function(){return{min:"0.4.27"}}},{key:"levels",get:function(){return this._levels||[]}},{key:"currentLevel",get:function(){return null===this._currentLevel||void 0===this._currentLevel?-1:this._currentLevel},set:function(e){this._currentLevel=e,this.trigger(t.Events.PLAYBACK_LEVEL_SWITCH_START),this.options.playback.hlsUseNextLevel?this._hls.nextLevel=this._currentLevel:this._hls.currentLevel=this._currentLevel}},{key:"isReady",get:function(){return this._isReadyState}},{key:"_startTime",get:function(){return this._playbackType===t.Playback.LIVE&&"EVENT"!==this._playlistType?this._extrapolatedStartTime:this._playableRegionStartTime}},{key:"_now",get:function(){return m()}},{key:"_extrapolatedStartTime",get:function(){if(!this._localStartTimeCorrelation)return this._playableRegionStartTime;var t=this._localStartTimeCorrelation,e=this._now-t.local,r=(t.remote+e)/1e3;return Math.min(r,this._playableRegionStartTime+this._extrapolatedWindowDuration)}},{key:"_extrapolatedEndTime",get:function(){var t=this._playableRegionStartTime+this._playableRegionDuration;if(!this._localEndTimeCorrelation)return t;var e=this._localEndTimeCorrelation,r=this._now-e.local,i=(e.remote+r)/1e3;return Math.max(t-this._extrapolatedWindowDuration,Math.min(i,t))}},{key:"_duration",get:function(){return this._extrapolatedEndTime-this._startTime}},{key:"_extrapolatedWindowDuration",get:function(){return null===this._segmentTargetDuration?0:this._extrapolatedWindowNumSegments*this._segmentTargetDuration}},{key:"bandwidthEstimate",get:function(){return this._hls&&this._hls.bandwidthEstimate}},{key:"defaultOptions",get:function(){return{preload:!0}}},{key:"customListeners",get:function(){return this.options.hlsPlayback&&this.options.hlsPlayback.customListeners||[]}},{key:"sourceMedia",get:function(){return this.options.src}},{key:"_setInitialState",value:function(){this._minDvrSize=void 0===this.options.hlsMinimumDvrSize?60:this.options.hlsMinimumDvrSize,this._extrapolatedWindowNumSegments=this.options.playback&&void 0!==this.options.playback.extrapolatedWindowNumSegments?this.options.playback.extrapolatedWindowNumSegments:2,this._playbackType=t.Playback.VOD,this._lastTimeUpdate={current:0,total:0},this._lastDuration=null,this._playableRegionStartTime=0,this._localStartTimeCorrelation=null,this._localEndTimeCorrelation=null,this._playableRegionDuration=0,this._programDateTime=0,this._durationExcludesAfterLiveSyncPoint=!1,this._segmentTargetDuration=null,this._playlistType=null,this._recoverAttemptsRemaining=this.options.hlsRecoverAttempts||16}},{key:"_setup",value:function(){this._destroyHLSInstance(),this._createHLSInstance(),this._listenHLSEvents(),this._attachHLSMedia()}},{key:"_destroyHLSInstance",value:function(){this._hls&&(this._manifestParsed=!1,this._ccIsSetup=!1,this._ccTracksUpdated=!1,this._setInitialState(),this._hls.destroy(),this._hls=null)}},{key:"_createHLSInstance",value:function(){var t=a({},this.options.playback.hlsjsConfig);this._hls=new i.default(t)}},{key:"_attachHLSMedia",value:function(){this._hls&&this._hls.attachMedia(this.el)}},{key:"_listenHLSEvents",value:function(){var t=this;this._hls&&(this._hls.once(i.default.Events.MEDIA_ATTACHED,(function(){t.options.hlsPlayback.preload&&t._hls.loadSource(t.options.src)})),this._hls.on(i.default.Events.MANIFEST_PARSED,(function(){return t._manifestParsed=!0})),this._hls.on(i.default.Events.LEVEL_LOADED,(function(e,r){return t._updatePlaybackType(e,r)})),this._hls.on(i.default.Events.LEVEL_UPDATED,(function(e,r){return t._onLevelUpdated(e,r)})),this._hls.on(i.default.Events.LEVEL_SWITCHING,(function(e,r){return t._onLevelSwitch(e,r)})),this._hls.on(i.default.Events.FRAG_CHANGED,(function(e,r){return t._onFragmentChanged(e,r)})),this._hls.on(i.default.Events.FRAG_LOADED,(function(e,r){return t._onFragmentLoaded(e,r)})),this._hls.on(i.default.Events.FRAG_PARSING_METADATA,(function(e,r){return t._onFragmentParsingMetadata(e,r)})),this._hls.on(i.default.Events.ERROR,(function(e,r){return t._onHLSJSError(e,r)})),this._hls.on(i.default.Events.SUBTITLE_TRACK_LOADED,(function(e,r){return t._onSubtitleLoaded(e,r)})),this._hls.on(i.default.Events.SUBTITLE_TRACKS_UPDATED,(function(){return t._ccTracksUpdated=!0})),this.bindCustomListeners())}},{key:"bindCustomListeners",value:function(){var t=this;this.customListeners.forEach((function(e){var r=e.eventName,i=e.once?"once":"on";r&&t._hls["".concat(i)](r,e.callback)}))}},{key:"unbindCustomListeners",value:function(){var t=this;this.customListeners.forEach((function(e){var r=e.eventName;r&&t._hls.off(r,e.callback)}))}},{key:"_onFragmentParsingMetadata",value:function(e,r){this.trigger(t.Events.Custom.PLAYBACK_FRAGMENT_PARSING_METADATA,{evt:e,data:r})}},{key:"render",value:function(){return this._ready(),p(u(d.prototype),"render",this).call(this)}},{key:"_ready",value:function(){this._isReadyState||(!this._hls&&this._setup(),this._isReadyState=!0,this.trigger(t.Events.PLAYBACK_READY,this.name))}},{key:"_recover",value:function(e,r,i){if(this._recoveredDecodingError)if(this._recoveredAudioCodecError){t.Log.error("hlsjs: failed to recover",{evt:e,data:r}),i.level=t.PlayerError.Levels.FATAL;var n=this.createError(i);this.trigger(t.Events.PLAYBACK_ERROR,n),this.stop()}else this._recoveredAudioCodecError=!0,this._hls.swapAudioCodec(),this._hls.recoverMediaError();else this._recoveredDecodingError=!0,this._hls.recoverMediaError()}},{key:"_setupSrc",value:function(t){}},{key:"_startTimeUpdateTimer",value:function(){var t=this;this._timeUpdateTimer||(this._timeUpdateTimer=setInterval((function(){t._onDurationChange(),t._onTimeUpdate()}),100))}},{key:"_stopTimeUpdateTimer",value:function(){this._timeUpdateTimer&&(clearInterval(this._timeUpdateTimer),this._timeUpdateTimer=null)}},{key:"getProgramDateTime",value:function(){return this._programDateTime}},{key:"getDuration",value:function(){return this._duration}},{key:"getCurrentTime",value:function(){return Math.max(0,this.el.currentTime-this._startTime)}},{key:"getStartTimeOffset",value:function(){return this._startTime}},{key:"seekPercentage",value:function(t){var e=t>0?this._duration*(t/100):this._duration;this.seek(e)}},{key:"seek",value:function(e){e<0&&(t.Log.warn("Attempt to seek to a negative time. Resetting to live point. Use seekToLivePoint() to seek to the live point."),e=this.getDuration()),this.dvrEnabled&&this._updateDvr(e<this.getDuration()-3),e+=this._startTime,this.el.currentTime=e}},{key:"seekToLivePoint",value:function(){this.seek(this.getDuration())}},{key:"_updateDvr",value:function(e){this.trigger(t.Events.PLAYBACK_DVR,e),this.trigger(t.Events.PLAYBACK_STATS_ADD,{dvr:e})}},{key:"_updateSettings",value:function(){this._playbackType===t.Playback.VOD?this.settings.left=["playpause","position","duration"]:this.dvrEnabled?this.settings.left=["playpause"]:this.settings.left=["playstop"],this.settings.seekEnabled=this.isSeekEnabled(),this.trigger(t.Events.PLAYBACK_SETTINGSUPDATE)}},{key:"_onHLSJSError",value:function(e,r){var n,a={code:"".concat(r.type,"_").concat(r.details),description:"".concat(this.name," error: type: ").concat(r.type,", details: ").concat(r.details),raw:r};if(r.response&&(a.description+=", response: ".concat(JSON.stringify(r.response))),r.fatal)if(this._recoverAttemptsRemaining>0)switch(this._recoverAttemptsRemaining-=1,r.type){case i.default.ErrorTypes.NETWORK_ERROR:switch(r.details){case i.default.ErrorDetails.MANIFEST_LOAD_ERROR:case i.default.ErrorDetails.MANIFEST_LOAD_TIMEOUT:case i.default.ErrorDetails.MANIFEST_PARSING_ERROR:case i.default.ErrorDetails.LEVEL_LOAD_ERROR:case i.default.ErrorDetails.LEVEL_LOAD_TIMEOUT:t.Log.error("hlsjs: unrecoverable network fatal error.",{evt:e,data:r}),n=this.createError(a),this.trigger(t.Events.PLAYBACK_ERROR,n),this.stop();break;default:t.Log.warn("hlsjs: trying to recover from network error.",{evt:e,data:r}),a.level=t.PlayerError.Levels.WARN,this._hls.startLoad()}break;case i.default.ErrorTypes.MEDIA_ERROR:t.Log.warn("hlsjs: trying to recover from media error.",{evt:e,data:r}),a.level=t.PlayerError.Levels.WARN,this._recover(e,r,a);break;default:t.Log.error("hlsjs: could not recover from error.",{evt:e,data:r}),n=this.createError(a),this.trigger(t.Events.PLAYBACK_ERROR,n),this.stop()}else t.Log.error("hlsjs: could not recover from error after maximum number of attempts.",{evt:e,data:r}),n=this.createError(a),this.trigger(t.Events.PLAYBACK_ERROR,n),this.stop();else{if(this.options.playback.triggerFatalErrorOnResourceDenied&&this._keyIsDenied(r))return t.Log.error("hlsjs: could not load decrypt key.",{evt:e,data:r}),n=this.createError(a),this.trigger(t.Events.PLAYBACK_ERROR,n),void this.stop();a.level=t.PlayerError.Levels.WARN,t.Log.warn("hlsjs: non-fatal error occurred",{evt:e,data:r})}}},{key:"_keyIsDenied",value:function(t){return t.type===i.default.ErrorTypes.NETWORK_ERROR&&t.details===i.default.ErrorDetails.KEY_LOAD_ERROR&&t.response&&t.response.code>=400}},{key:"_onTimeUpdate",value:function(){var e={current:this.getCurrentTime(),total:this.getDuration(),firstFragDateTime:this.getProgramDateTime()};this._lastTimeUpdate&&e.current===this._lastTimeUpdate.current&&e.total===this._lastTimeUpdate.total||(this._lastTimeUpdate=e,this.trigger(t.Events.PLAYBACK_TIMEUPDATE,e,this.name))}},{key:"_onDurationChange",value:function(){var t=this.getDuration();this._lastDuration!==t&&(this._lastDuration=t,p(u(d.prototype),"_onDurationChange",this).call(this))}},{key:"_onProgress",value:function(){if(this.el.buffered.length){for(var e=[],r=0,i=0;i<this.el.buffered.length;i++)e=[].concat(f(e),[{start:Math.max(0,this.el.buffered.start(i)-this._playableRegionStartTime),end:Math.max(0,this.el.buffered.end(i)-this._playableRegionStartTime)}]),this.el.currentTime>=e[i].start&&this.el.currentTime<=e[i].end&&(r=i);var n={start:e[r].start,current:e[r].end,total:this.getDuration()};this.trigger(t.Events.PLAYBACK_PROGRESS,n,e)}}},{key:"load",value:function(t){this._stopTimeUpdateTimer(),this.options.src=t,this._setup()}},{key:"play",value:function(){!this._hls&&this._setup(),!this._manifestParsed&&!this.options.hlsPlayback.preload&&this._hls.loadSource(this.options.src),p(u(d.prototype),"play",this).call(this),this._startTimeUpdateTimer()}},{key:"pause",value:function(){this._hls&&(this.el.pause(),this.dvrEnabled&&this._updateDvr(!0))}},{key:"stop",value:function(){this._stopTimeUpdateTimer(),this._hls&&p(u(d.prototype),"stop",this).call(this),this._destroyHLSInstance()}},{key:"destroy",value:function(){this._stopTimeUpdateTimer(),this._destroyHLSInstance(),p(u(d.prototype),"destroy",this).call(this)}},{key:"_updatePlaybackType",value:function(e,r){this._playbackType=r.details.live?t.Playback.LIVE:t.Playback.VOD,this._onLevelUpdated(e,r),this._ccTracksUpdated&&this._playbackType===t.Playback.LIVE&&this.hasClosedCaptionsTracks&&this._onSubtitleLoaded()}},{key:"_fillLevels",value:function(){this._levels=this._hls.levels.map((function(t,e){return{id:e,level:t,label:"".concat(t.bitrate/1e3,"Kbps")}})),this.trigger(t.Events.PLAYBACK_LEVELS_AVAILABLE,this._levels)}},{key:"_onLevelUpdated",value:function(e,r){this._segmentTargetDuration=r.details.targetduration,this._playlistType=r.details.type||null;var n=!1,a=!1,o=r.details.fragments,s=this._playableRegionStartTime,l=this._playableRegionDuration;if(0!==o.length){if(o[0].rawProgramDateTime&&(this._programDateTime=o[0].rawProgramDateTime),this._playableRegionStartTime!==o[0].start&&(n=!0,this._playableRegionStartTime=o[0].start),n)if(this._localStartTimeCorrelation){var u=this._localStartTimeCorrelation,c=this._now-u.local,h=(u.remote+c)/1e3;h<o[0].start?this._localStartTimeCorrelation={local:this._now,remote:1e3*o[0].start}:h>s+this._extrapolatedWindowDuration&&(this._localStartTimeCorrelation={local:this._now,remote:1e3*Math.max(o[0].start,s+this._extrapolatedWindowDuration)})}else this._localStartTimeCorrelation={local:this._now,remote:1e3*(o[0].start+this._extrapolatedWindowDuration/2)};var _=r.details.totalduration;if(this._playbackType===t.Playback.LIVE){var d=r.details.targetduration*((this.options.playback.hlsjsConfig||{}).liveSyncDurationCount||i.default.DefaultConfig.liveSyncDurationCount);d<=_?(_-=d,this._durationExcludesAfterLiveSyncPoint=!0):this._durationExcludesAfterLiveSyncPoint=!1}_!==this._playableRegionDuration&&(a=!0,this._playableRegionDuration=_);var p=o[0].start+_,f=s+l;if(p!==f)if(this._localEndTimeCorrelation){var y=this._localEndTimeCorrelation,v=this._now-y.local,m=(y.remote+v)/1e3;m>p?this._localEndTimeCorrelation={local:this._now,remote:1e3*p}:m<p-this._extrapolatedWindowDuration?this._localEndTimeCorrelation={local:this._now,remote:1e3*(p-this._extrapolatedWindowDuration)}:m>f&&(this._localEndTimeCorrelation={local:this._now,remote:1e3*f})}else this._localEndTimeCorrelation={local:this._now,remote:1e3*p};a&&this._onDurationChange(),n&&this._onProgress()}}},{key:"_onFragmentChanged",value:function(e,r){this.trigger(t.Events.Custom.PLAYBACK_FRAGMENT_CHANGED,r)}},{key:"_onFragmentLoaded",value:function(e,r){this.trigger(t.Events.PLAYBACK_FRAGMENT_LOADED,r)}},{key:"_onSubtitleLoaded",value:function(){if(!this._ccIsSetup){this.trigger(t.Events.PLAYBACK_SUBTITLE_AVAILABLE);var e=this._playbackType===t.Playback.LIVE?-1:this.closedCaptionsTrackId;this.closedCaptionsTrackId=e,this._ccIsSetup=!0}}},{key:"_onLevelSwitch",value:function(e,r){this.levels.length||this._fillLevels(),this.trigger(t.Events.PLAYBACK_LEVEL_SWITCH_END),this.trigger(t.Events.PLAYBACK_LEVEL_SWITCH,r);var i=this._hls.levels[r.level];i&&(this.highDefinition=i.height>=720||i.bitrate/1e3>=2e3,this.trigger(t.Events.PLAYBACK_HIGHDEFINITIONUPDATE,this.highDefinition),this.trigger(t.Events.PLAYBACK_BITRATE,{height:i.height,width:i.width,bandwidth:i.bitrate,bitrate:i.bitrate,level:r.level}))}},{key:"dvrEnabled",get:function(){return this._durationExcludesAfterLiveSyncPoint&&this._duration>=this._minDvrSize&&this.getPlaybackType()===t.Playback.LIVE}},{key:"getPlaybackType",value:function(){return this._playbackType}},{key:"isSeekEnabled",value:function(){return this._playbackType===t.Playback.VOD||this.dvrEnabled}}])&&s(r.prototype,n),l&&s(r,l),Object.defineProperty(r,"prototype",{writable:!1}),d}(t.HTML5Video);return E.canPlay=function(t,e){var r=t.split("?")[0].match(/.*\.(.*)$/)||[],n=r.length>1&&"m3u8"===r[1].toLowerCase()||g(e,["application/vnd.apple.mpegurl","application/x-mpegURL"]);return!(!i.default.isSupported()||!n)},E}(Clappr);
2
2
  //# sourceMappingURL=hlsjs-playback.external.min.js.map