|
|
@@ -29,7 +29,7 @@ var Player = function(url, options) {
|
|
29
|
29
|
|
|
30
|
30
|
if (!options.disableWebAssembly && JSMpeg.WASMModule.IsSupported()) {
|
|
31
|
31
|
this.wasmModule = new JSMpeg.WASMModule();
|
|
32
|
|
- options.wasmModule =this.wasmModule;
|
|
|
32
|
+ options.wasmModule = this.wasmModule;
|
|
33
|
33
|
}
|
|
34
|
34
|
|
|
35
|
35
|
if (options.video !== false) {
|
|
|
@@ -63,6 +63,7 @@ var Player = function(url, options) {
|
|
63
|
63
|
set: this.setVolume
|
|
64
|
64
|
});
|
|
65
|
65
|
|
|
|
66
|
+ this.paused = true;
|
|
66
|
67
|
this.unpauseOnShow = false;
|
|
67
|
68
|
if (options.pauseWhenHidden !== false) {
|
|
68
|
69
|
document.addEventListener('visibilitychange', this.showHide.bind(this));
|
|
|
@@ -104,14 +105,25 @@ Player.prototype.showHide = function(ev) {
|
|
104
|
105
|
};
|
|
105
|
106
|
|
|
106
|
107
|
Player.prototype.play = function(ev) {
|
|
|
108
|
+ if (this.animationId) {
|
|
|
109
|
+ return;
|
|
|
110
|
+ }
|
|
|
111
|
+
|
|
107
|
112
|
this.animationId = requestAnimationFrame(this.update.bind(this));
|
|
108
|
113
|
this.wantsToPlay = true;
|
|
|
114
|
+ this.paused = false;
|
|
109
|
115
|
};
|
|
110
|
116
|
|
|
111
|
117
|
Player.prototype.pause = function(ev) {
|
|
|
118
|
+ if (this.paused) {
|
|
|
119
|
+ return;
|
|
|
120
|
+ }
|
|
|
121
|
+
|
|
112
|
122
|
cancelAnimationFrame(this.animationId);
|
|
|
123
|
+ this.animationId = null;
|
|
113
|
124
|
this.wantsToPlay = false;
|
|
114
|
125
|
this.isPlaying = false;
|
|
|
126
|
+ this.paused = true;
|
|
115
|
127
|
|
|
116
|
128
|
if (this.audio && this.audio.canPlay) {
|
|
117
|
129
|
// Seek to the currentTime again - audio may already be enqueued a bit
|
|
|
@@ -119,6 +131,10 @@ Player.prototype.pause = function(ev) {
|
|
119
|
131
|
this.audioOut.stop();
|
|
120
|
132
|
this.seek(this.currentTime);
|
|
121
|
133
|
}
|
|
|
134
|
+
|
|
|
135
|
+ if (this.options.onPause) {
|
|
|
136
|
+ this.options.onPause(this);
|
|
|
137
|
+ }
|
|
122
|
138
|
};
|
|
123
|
139
|
|
|
124
|
140
|
Player.prototype.getVolume = function() {
|
|
|
@@ -186,6 +202,10 @@ Player.prototype.update = function() {
|
|
186
|
202
|
if (!this.isPlaying) {
|
|
187
|
203
|
this.isPlaying = true;
|
|
188
|
204
|
this.startTime = JSMpeg.Now() - this.currentTime;
|
|
|
205
|
+
|
|
|
206
|
+ if (this.options.onPlay) {
|
|
|
207
|
+ this.options.onPlay(this);
|
|
|
208
|
+ }
|
|
189
|
209
|
}
|
|
190
|
210
|
|
|
191
|
211
|
if (this.options.streaming) {
|
|
|
@@ -219,6 +239,13 @@ Player.prototype.updateForStreaming = function() {
|
|
219
|
239
|
}
|
|
220
|
240
|
};
|
|
221
|
241
|
|
|
|
242
|
+Player.prototype.nextFrame = function() {
|
|
|
243
|
+ if (this.source.established && this.video) {
|
|
|
244
|
+ return this.video.decode();
|
|
|
245
|
+ }
|
|
|
246
|
+ return false;
|
|
|
247
|
+};
|
|
|
248
|
+
|
|
222
|
249
|
Player.prototype.updateForStaticFile = function() {
|
|
223
|
250
|
var notEnoughData = false,
|
|
224
|
251
|
headroom = 0;
|
|
|
@@ -275,8 +302,17 @@ Player.prototype.updateForStaticFile = function() {
|
|
275
|
302
|
}
|
|
276
|
303
|
else {
|
|
277
|
304
|
this.pause();
|
|
|
305
|
+ if (this.options.onEnded) {
|
|
|
306
|
+ this.options.onEnded(this);
|
|
|
307
|
+ }
|
|
278
|
308
|
}
|
|
279
|
309
|
}
|
|
|
310
|
+
|
|
|
311
|
+ // If there's not enough data and the source is not completed, we have
|
|
|
312
|
+ // just stalled.
|
|
|
313
|
+ else if (notEnoughData && this.options.onStalled) {
|
|
|
314
|
+ this.options.onStalled(this);
|
|
|
315
|
+ }
|
|
280
|
316
|
};
|
|
281
|
317
|
|
|
282
|
318
|
return Player;
|