shaka-player 4.8.2 → 4.8.3

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.
@@ -1519,11 +1519,14 @@ shaka.extern.AdsConfiguration;
1519
1519
  * @property {boolean} enabled
1520
1520
  * If true, enable adaptation by the current AbrManager. Defaults to true.
1521
1521
  * @property {boolean} useNetworkInformation
1522
- * If true, use Network Information API in the current AbrManager.
1522
+ * If true, use the Network Information API in the current AbrManager, if it
1523
+ * is available in the browser environment. If the Network Information API is
1524
+ * used, Shaka Player will ignore the defaultBandwidthEstimate config.
1523
1525
  * Defaults to true.
1524
1526
  * @property {number} defaultBandwidthEstimate
1525
1527
  * The default bandwidth estimate to use if there is not enough data, in
1526
- * bit/sec.
1528
+ * bit/sec. Only used if useNetworkInformation is false, or if the Network
1529
+ * Information API is not available.
1527
1530
  * @property {shaka.extern.Restrictions} restrictions
1528
1531
  * The restrictions to apply to ABR decisions. These are "soft" restrictions.
1529
1532
  * Any track that fails to meet these restrictions will not be selected
@@ -6,6 +6,7 @@
6
6
 
7
7
  goog.provide('shaka.media.PlayRateController');
8
8
 
9
+ goog.require('goog.asserts');
9
10
  goog.require('shaka.log');
10
11
  goog.require('shaka.util.IReleasable');
11
12
  goog.require('shaka.util.Timer');
@@ -27,6 +28,9 @@ shaka.media.PlayRateController = class {
27
28
  /** @private {?shaka.media.PlayRateController.Harness} */
28
29
  this.harness_ = harness;
29
30
 
31
+ /** @private {boolean} */
32
+ this.isBuffering_ = false;
33
+
30
34
  /** @private {number} */
31
35
  this.rate_ = this.harness_.getRate();
32
36
 
@@ -51,15 +55,25 @@ shaka.media.PlayRateController = class {
51
55
  }
52
56
 
53
57
  /**
54
- * Set the playback rate.
58
+ * Sets the buffering flag, which controls the effective playback rate.
59
+ *
60
+ * @param {boolean} isBuffering If true, forces playback rate to 0 internally.
61
+ */
62
+ setBuffering(isBuffering) {
63
+ this.isBuffering_ = isBuffering;
64
+ this.apply_();
65
+ }
66
+
67
+ /**
68
+ * Set the playback rate. This rate will only be used as provided when the
69
+ * player is not buffering. You should never set the rate to 0.
55
70
  *
56
71
  * @param {number} rate
57
72
  */
58
73
  set(rate) {
59
- if (this.rate_ != rate) {
60
- this.rate_ = rate;
61
- this.apply_();
62
- }
74
+ goog.asserts.assert(rate != 0, 'Should never set rate of 0 explicitly!');
75
+ this.rate_ = rate;
76
+ this.apply_();
63
77
  }
64
78
 
65
79
  /**
@@ -93,11 +107,14 @@ shaka.media.PlayRateController = class {
93
107
  // Always stop the timer. We may not start it again.
94
108
  this.timer_.stop();
95
109
 
96
- shaka.log.v1('Changing effective playback rate to', this.rate_);
110
+ /** @type {number} */
111
+ const rate = this.calculateCurrentRate_();
112
+
113
+ shaka.log.v1('Changing effective playback rate to', rate);
97
114
 
98
- if (this.rate_ >= 0) {
115
+ if (rate >= 0) {
99
116
  try {
100
- this.applyRate_(this.rate_);
117
+ this.applyRate_(rate);
101
118
  return;
102
119
  } catch (e) {
103
120
  // Fall through to the next clause.
@@ -117,6 +134,17 @@ shaka.media.PlayRateController = class {
117
134
  this.applyRate_(0);
118
135
  }
119
136
 
137
+ /**
138
+ * Calculate the rate that the controller wants the media element to have
139
+ * based on the current state of the controller.
140
+ *
141
+ * @return {number}
142
+ * @private
143
+ */
144
+ calculateCurrentRate_() {
145
+ return this.isBuffering_ ? 0 : this.rate_;
146
+ }
147
+
120
148
  /**
121
149
  * If the new rate is different than the media element's playback rate, this
122
150
  * will change the playback rate. If the rate does not need to change, it will
@@ -174,6 +174,9 @@ shaka.media.StallDetector.MediaElementImplementation = class {
174
174
  if (this.mediaElement_.paused) {
175
175
  return false;
176
176
  }
177
+ if (this.mediaElement_.playbackRate == 0) {
178
+ return false;
179
+ }
177
180
 
178
181
  // If we have don't have enough content, we are not stalled, we are
179
182
  // buffering.
package/lib/player.js CHANGED
@@ -622,6 +622,12 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
622
622
  */
623
623
  this.playRateController_ = null;
624
624
 
625
+ // We use the buffering observer and timer to track when we move from having
626
+ // enough buffered content to not enough. They only exist when content has
627
+ // been loaded and are not re-used between loads.
628
+ /** @private {shaka.util.Timer} */
629
+ this.bufferPoller_ = null;
630
+
625
631
  /** @private {shaka.media.BufferingObserver} */
626
632
  this.bufferObserver_ = null;
627
633
 
@@ -1228,6 +1234,11 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
1228
1234
  this.playheadObservers_ = null;
1229
1235
  }
1230
1236
 
1237
+ if (this.bufferPoller_) {
1238
+ this.bufferPoller_.stop();
1239
+ this.bufferPoller_ = null;
1240
+ }
1241
+
1231
1242
  // Stop the parser early. Since it is at the start of the pipeline, it
1232
1243
  // should be start early to avoid is pushing new data downstream.
1233
1244
  if (this.parser_) {
@@ -3101,6 +3112,10 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
3101
3112
  !this.bufferObserver_,
3102
3113
  'No buffering observer should exist before initialization.');
3103
3114
 
3115
+ goog.asserts.assert(
3116
+ !this.bufferPoller_,
3117
+ 'No buffer timer should exist before initialization.');
3118
+
3104
3119
  // Give dummy values, will be updated below.
3105
3120
  this.bufferObserver_ = new shaka.media.BufferingObserver(1, 2);
3106
3121
 
@@ -3110,6 +3125,9 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
3110
3125
  this.updateBufferingSettings_(rebufferingGoal);
3111
3126
  this.updateBufferState_();
3112
3127
 
3128
+ this.bufferPoller_ = new shaka.util.Timer(() => {
3129
+ this.pollBufferState_();
3130
+ }).tickEvery(/* seconds= */ 0.25);
3113
3131
  this.loadEventManager_.listen(mediaElement, 'waiting',
3114
3132
  (e) => this.pollBufferState_());
3115
3133
  this.loadEventManager_.listen(mediaElement, 'stalled',
@@ -5833,6 +5851,7 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
5833
5851
  const loaded = this.stats_ && this.bufferObserver_ && this.playhead_;
5834
5852
 
5835
5853
  if (loaded) {
5854
+ this.playRateController_.setBuffering(isBuffering);
5836
5855
  if (this.cmcdManager_) {
5837
5856
  this.cmcdManager_.setBuffering(isBuffering);
5838
5857
  }
@@ -7182,7 +7201,7 @@ shaka.Player.TYPICAL_BUFFERING_THRESHOLD_ = 0.5;
7182
7201
  * @export
7183
7202
  */
7184
7203
  // eslint-disable-next-line no-useless-concat
7185
- shaka.Player.version = 'v4.8.2' + '-uncompiled'; // x-release-please-version
7204
+ shaka.Player.version = 'v4.8.3' + '-uncompiled'; // x-release-please-version
7186
7205
 
7187
7206
  // Initialize the deprecation system using the version string we just set
7188
7207
  // on the player.
@@ -684,8 +684,8 @@ shaka.util.Platform = class {
684
684
  /** @type {{screenWidth: number, screenHeight: number}} */(
685
685
  JSON.parse(window.PalmSystem.deviceInfo));
686
686
  // WebOS has always been able to do 1080p. Assume a 1080p limit.
687
- maxResolution.width = Math.max(1920, deviceInfo.screenWidth);
688
- maxResolution.height = Math.max(1080, deviceInfo.screenHeight);
687
+ maxResolution.width = Math.max(1920, deviceInfo['screenWidth']);
688
+ maxResolution.height = Math.max(1080, deviceInfo['screenHeight']);
689
689
  } catch (e) {
690
690
  shaka.log.alwaysWarn('WebOS: Error detecting screen size, default ' +
691
691
  'screen size 1920x1080.');
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "shaka-player",
3
3
  "description": "DASH/EME video player library",
4
- "version": "4.8.2",
4
+ "version": "4.8.3",
5
5
  "homepage": "https://github.com/shaka-project/shaka-player",
6
6
  "author": "Google",
7
7
  "maintainers": [