Skip to content

Commit d14d9f4

Browse files
committed
Added onAccess and onError signals and tidied up the stream handling.
1 parent a24a227 commit d14d9f4

1 file changed

Lines changed: 24 additions & 4 deletions

File tree

src/gameobjects/Video.js

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,24 @@ Phaser.Video = function (game, key, captureAudio, width, height) {
131131
*/
132132
this.onComplete = new Phaser.Signal();
133133

134+
/**
135+
* @property {Phaser.Signal} onAccess - This signal is dispatched if the user allows access to their webcam.
136+
*/
137+
this.onAccess = new Phaser.Signal();
138+
139+
/**
140+
* @property {Phaser.Signal} onError - This signal is dispatched if an error occurs either getting permission to use the webcam (for a Video Stream) or when trying to play back a video file.
141+
*/
142+
this.onError = new Phaser.Signal();
143+
134144
/**
135145
* @property {boolean} touchLocked - true if this video is currently locked awaiting a touch event. This happens on some mobile devices, such as iOS.
136146
* @default
137147
*/
138148
this.touchLocked = false;
139149

140150
/**
141-
* @property {object} videoStream - The Video Stream data. Only set if this Video is streaming from the webcam via `createVideoStream`.
151+
* @property {MediaStream} videoStream - The Video Stream data. Only set if this Video is streaming from the webcam via `createVideoStream`.
142152
*/
143153
this.videoStream = null;
144154

@@ -206,10 +216,10 @@ Phaser.Video.prototype = {
206216
* As soon as this method is called the user will be prompted by their browser to "Allow" access to the webcam.
207217
* If they allow it the webcam feed is directed to this Video. Call `Video.play` to start the stream.
208218
*
209-
* If they block the webcam a console warning will be displayed containing the NavigatorUserMediaError event.
219+
* If they block the webcam the onError signal will be dispatched containing the NavigatorUserMediaError event.
210220
*
211221
* You can optionally set a width and height for the stream. If set the input will be cropped to these dimensions.
212-
* If not given as soon as the stream has enough data the video dimensions will be changed to match the webcam device.
222+
* If not given then as soon as the stream has enough data the video dimensions will be changed to match the webcam device.
213223
* You can listen for this with the onChangeSource signal.
214224
*
215225
* @method Phaser.Video#createVideoStream
@@ -258,10 +268,12 @@ Phaser.Video.prototype = {
258268

259269
_this.video.addEventListener('loadeddata', function (event) { _this.updateTexture(width, height); }, true);
260270

271+
_this.onAccess.dispatch(_this);
272+
261273
};
262274

263275
var _streamError = function(e) {
264-
console.warn('Stream Error', e);
276+
_this.onError.dispatch(_this, e);
265277
}
266278

267279
navigator.getUserMedia({ audio: captureAudio, video: true }, _streamStart, _streamError);
@@ -411,6 +423,8 @@ Phaser.Video.prototype = {
411423
* If the video hasn't finished downloading calling `Video.stop` will not abort the download. To do that you need to
412424
* call `Video.destroy` instead.
413425
*
426+
* If you are using a video stream from a webcam then calling Stop will disconnect the MediaStream session and disable the webcam.
427+
*
414428
* @method Phaser.Video#stop
415429
* @return {Phaser.Video} This Video object for method chaining.
416430
*/
@@ -691,6 +705,12 @@ Phaser.Video.prototype = {
691705

692706
return true;
693707

708+
},
709+
710+
snapshot: function () {
711+
712+
713+
694714
},
695715

696716
/**

0 commit comments

Comments
 (0)