You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* The video file must have already been loaded into the Phaser.Cache.
422
-
* The key given is the key you used when the video was preloaded.
423
421
* This will return a Phaser.Video object which you can pass to a Sprite to be used as a texture.
424
-
* If you wish to create a Sprite with a Video texture automatically you can use `GameObjectFactory.videoSprite`.
425
422
*
426
423
* @method Phaser.GameObjectFactory#video
427
-
* @param {string} key - The key of the file in the Phaser.Cache that this video will use.
424
+
* @param {string|null} key - The key of the video file in the Phaser.Cache that the Video object will use. If null a `getUserMedia` video stream will be established instead.
425
+
* @param {boolean} [captureAudio=false] - If the key is null this controls if audio should be captured along with video in the video stream.
426
+
* @param {integer} [width] - If the key is null this width is used to create the video stream. If not provided the video width will be set to the width of the webcam input source.
427
+
* @param {integer} [height] - If the key is null this height is used to create the video stream. If not provided the video height will be set to the height of the webcam input source.
428
428
* @return {Phaser.Video} The newly created Video object.
* A Video object that takes a previously loaded Video from the Phaser Cache and handles playback of it.
9
9
*
10
+
* Alternatively it takes a getUserMedia feed from an active webcam and streams the contents of that to
11
+
* the Video instead.
12
+
*
10
13
* This can be applied to a Sprite as a texture. If multiple Sprites share the same Video texture and playback
11
14
* changes (i.e. you pause the video, or seek to a new time) then this change will be seen across all Sprites simultaneously.
12
15
*
@@ -24,45 +27,61 @@
24
27
* @class Phaser.Video
25
28
* @constructor
26
29
* @param {Phaser.Game} game - A reference to the currently running game.
27
-
* @param {string} key - The key of the video file stored in the Phaser.Cache that this Video object should use.
30
+
* @param {string|null} key - The key of the video file in the Phaser.Cache that this Video object should use. If null a `getUserMedia` video stream will be established instead.
31
+
* @param {boolean} [captureAudio=false] - If the key is null this controls if audio should be captured along with video in the video stream.
32
+
* @param {integer} [width] - If the key is null this width is used to create the video stream. If not provided the video width will be set to the width of the webcam input source.
33
+
* @param {integer} [height] - If the key is null this height is used to create the video stream. If not provided the video height will be set to the height of the webcam input source.
* @property {number} width - The width of the video in pixels.
59
-
*/
60
-
this.width=this.video.videoWidth;
73
+
if(_video.isBlob)
74
+
{
75
+
this.createVideoFromBlob(_video.data);
76
+
}
77
+
else
78
+
{
79
+
this.video=_video.data;
80
+
}
61
81
62
-
/**
63
-
* @property {number} height - The height of the video in pixels.
64
-
*/
65
-
this.height=this.video.videoHeight;
82
+
this.width=this.video.videoWidth;
83
+
this.height=this.video.videoHeight;
84
+
}
66
85
67
86
/**
68
87
* @property {PIXI.BaseTexture} baseTexture - The PIXI.BaseTexture.
@@ -118,6 +137,11 @@ Phaser.Video = function (game, key) {
118
137
*/
119
138
this.touchLocked=false;
120
139
140
+
/**
141
+
* @property {object} videoStream - The Video Stream data. Only set if this Video is streaming from the webcam via `createVideoStream`.
142
+
*/
143
+
this.videoStream=null;
144
+
121
145
/**
122
146
* @property {boolean} _codeMuted - Internal mute tracking var.
123
147
* @private
@@ -166,13 +190,86 @@ Phaser.Video = function (game, key) {
166
190
}
167
191
else
168
192
{
169
-
_video.locked=false;
193
+
if(_video)
194
+
{
195
+
_video.locked=false;
196
+
}
170
197
}
171
198
172
199
};
173
200
174
201
Phaser.Video.prototype={
175
202
203
+
/**
204
+
* Instead of playing a video file this method allows you to stream video data from an attached webcam.
205
+
*
206
+
* As soon as this method is called the user will be prompted by their browser to "Allow" access to the webcam.
207
+
* If they allow it the webcam feed is directed to this Video. Call `Video.play` to start the stream.
208
+
*
209
+
* If they block the webcam a console warning will be displayed containing the NavigatorUserMediaError event.
210
+
*
211
+
* 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.
213
+
* You can listen for this with the onChangeSource signal.
214
+
*
215
+
* @method Phaser.Video#createVideoStream
216
+
* @param {boolean} [captureAudio=false] - Controls if audio should be captured along with video in the video stream.
217
+
* @param {integer} [width] - The width is used to create the video stream. If not provided the video width will be set to the width of the webcam input source.
218
+
* @param {integer} [height] - The height is used to create the video stream. If not provided the video height will be set to the height of the webcam input source.
219
+
* @return {Phaser.Video} This Video object for method chaining.
0 commit comments