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
Refactored Video constructor significantly - you can no longer create a webcam stream from the constructor, as it doesn't give you time to respond to onAccess and onError signals in Firefox. Instead call startMediaStream directly having set-up your signal listeners first.
startMediaStream now has a chance to dispatch the onError signal if the webcam has been blocked entirely by the browser (auto-block or remembered block). autoPlay attribute removed to stop Firefox throwing a "Invalid URI. Load of media resource failed" error.
Tidied up Video.destroy to properly remove video element from the DOM.
* This will return a Phaser.Video object which you can pass to a Sprite to be used as a texture.
451
451
*
452
452
* @method Phaser.GameObjectFactory#video
453
-
* @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.
454
-
* @param {boolean} [captureAudio=false] - If the key is null this controls if audio should be captured along with video in the video stream.
455
-
* @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.
456
-
* @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.
453
+
* @param {string|null} key - The key of the video file in the Phaser.Cache that this Video object will play. Set to `null` or leave undefined if you wish to use a webcam as the source. See `startMediaStream` to start webcam capture.
457
454
* @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
10
* Alternatively it takes a getUserMedia feed from an active webcam and streams the contents of that to
11
-
* the Video instead.
11
+
* the Video instead (see `startMediaStream` method)
12
12
*
13
-
* This can be applied to a Sprite as a texture. If multiple Sprites share the same Video texture and playback
13
+
* The video can then be applied to a Sprite as a texture. If multiple Sprites share the same Video texture and playback
14
14
* changes (i.e. you pause the video, or seek to a new time) then this change will be seen across all Sprites simultaneously.
15
15
*
16
16
* Due to a bug in IE11 you cannot play a video texture to a Sprite in WebGL. For IE11 force Canvas mode.
@@ -29,43 +29,84 @@
29
29
* @class Phaser.Video
30
30
* @constructor
31
31
* @param {Phaser.Game} game - A reference to the currently running game.
32
-
* @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.
33
-
* @param {boolean} [captureAudio=false] - If the key is null this controls if audio should be captured along with video in the video stream.
34
-
* @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.
35
-
* @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.
32
+
* @param {string|null} [key=null] - The key of the video file in the Phaser.Cache that this Video object will play. Set to `null` or leave undefined if you wish to use a webcam as the source. See `startMediaStream` to start webcam capture.
* @property {Phaser.Game} game - A reference to the currently running game.
44
40
*/
45
41
this.game=game;
46
42
47
43
/**
48
-
* @property {string} key - The key of the Video in the Cache, if stored there.
44
+
* @property {string} key - The key of the Video in the Cache, if stored there. Will be `null` if this Video is using the webcam instead.
45
+
* @default null
49
46
*/
50
47
this.key=key;
51
48
52
49
/**
53
50
* @property {number} width - The width of the video in pixels.
51
+
* @default
54
52
*/
55
-
this.width=(width) ? width : 0;
53
+
this.width=320;
56
54
57
55
/**
58
56
* @property {number} height - The height of the video in pixels.
57
+
* @default
58
+
*/
59
+
this.height=240;
60
+
61
+
/**
62
+
* @property {number} type - The const type of this object.
63
+
* @default
64
+
*/
65
+
this.type=Phaser.VIDEO;
66
+
67
+
/**
68
+
* @property {boolean} disableTextureUpload - If true this video will never send its image data to the GPU when its dirty flag is true. This only applies in WebGL.
69
+
*/
70
+
this.disableTextureUpload=false;
71
+
72
+
/**
73
+
* @property {boolean} touchLocked - true if this video is currently locked awaiting a touch event. This happens on some mobile devices, such as iOS.
74
+
* @default
75
+
*/
76
+
this.touchLocked=false;
77
+
78
+
/**
79
+
* @property {Phaser.Signal} onPlay - This signal is dispatched when the Video starts to play. It sends 3 parameters: a reference to the Video object, if the video is set to loop or not and the playback rate.
80
+
*/
81
+
this.onPlay=newPhaser.Signal();
82
+
83
+
/**
84
+
* @property {Phaser.Signal} onChangeSource - This signal is dispatched if the Video source is changed. It sends 3 parameters: a reference to the Video object and the new width and height of the new video source.
85
+
*/
86
+
this.onChangeSource=newPhaser.Signal();
87
+
88
+
/**
89
+
* @property {Phaser.Signal} onComplete - This signal is dispatched when the Video completes playback, i.e. enters an 'ended' state. Videos set to loop will never dispatch this signal.
90
+
*/
91
+
this.onComplete=newPhaser.Signal();
92
+
93
+
/**
94
+
* @property {Phaser.Signal} onAccess - This signal is dispatched if the user allows access to their webcam.
95
+
*/
96
+
this.onAccess=newPhaser.Signal();
97
+
98
+
/**
99
+
* @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.
59
100
*/
60
-
this.height=(height) ? height : 0;
101
+
this.onError=newPhaser.Signal();
61
102
62
103
/**
63
104
* @property {HTMLVideoElement} video - The HTML Video Element that is added to the document.
64
105
*/
65
106
this.video=null;
66
107
67
108
/**
68
-
* @property {MediaStream} videoStream - The Video Stream data. Only set if this Video is streaming from the webcam via `createVideoStream`.
109
+
* @property {MediaStream} videoStream - The Video Stream data. Only set if this Video is streaming from the webcam via `startMediaStream`.
* @property {number} type - The const type of this object.
128
-
* @default
129
-
*/
130
-
this.type=Phaser.VIDEO;
131
-
132
-
/**
133
-
* @property {boolean} disableTextureUpload - If true this video will never send its image data to the GPU when its dirty flag is true. This only applies in WebGL.
134
-
*/
135
-
this.disableTextureUpload=false;
136
-
137
-
/**
138
-
* @property {Phaser.Signal} onPlay - This signal is dispatched when the Video starts to play. It sends 3 parameters: a reference to the Video object, if the video is set to loop or not and the playback rate.
139
-
*/
140
-
this.onPlay=newPhaser.Signal();
141
-
142
-
/**
143
-
* @property {Phaser.Signal} onChangeSource - This signal is dispatched if the Video source is changed. It sends 3 parameters: a reference to the Video object and the new width and height of the new video source.
144
-
*/
145
-
this.onChangeSource=newPhaser.Signal();
146
-
147
-
/**
148
-
* @property {Phaser.Signal} onComplete - This signal is dispatched when the Video completes playback, i.e. enters an 'ended' state. Videos set to loop will never dispatch this signal.
149
-
*/
150
-
this.onComplete=newPhaser.Signal();
151
-
152
-
/**
153
-
* @property {Phaser.Signal} onAccess - This signal is dispatched if the user allows access to their webcam.
154
-
*/
155
-
this.onAccess=newPhaser.Signal();
156
-
157
-
/**
158
-
* @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.
159
-
*/
160
-
this.onError=newPhaser.Signal();
161
-
162
-
/**
163
-
* @property {boolean} touchLocked - true if this video is currently locked awaiting a touch event. This happens on some mobile devices, such as iOS.
164
-
* @default
165
-
*/
166
-
this.touchLocked=false;
167
-
168
163
/**
169
164
* A snapshot grabbed from the video. This is initially black. Populate it by calling Video.grab().
170
165
* When called the BitmapData is updated with a grab taken from the current video playing or active video stream.
@@ -244,33 +239,33 @@ Phaser.Video.prototype = {
244
239
* As soon as this method is called the user will be prompted by their browser to "Allow" access to the webcam.
245
240
* If they allow it the webcam feed is directed to this Video. Call `Video.play` to start the stream.
246
241
*
247
-
* If they block the webcam the onError signal will be dispatched containing the NavigatorUserMediaError event.
242
+
* If they block the webcam the onError signal will be dispatched containing the NavigatorUserMediaError
243
+
* or MediaStreamError event.
248
244
*
249
245
* You can optionally set a width and height for the stream. If set the input will be cropped to these dimensions.
250
246
* If not given then as soon as the stream has enough data the video dimensions will be changed to match the webcam device.
251
247
* You can listen for this with the onChangeSource signal.
252
248
*
253
-
* @method Phaser.Video#createVideoStream
249
+
* @method Phaser.Video#startMediaStream
254
250
* @param {boolean} [captureAudio=false] - Controls if audio should be captured along with video in the video stream.
255
251
* @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.
256
252
* @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.
257
-
* @return {Phaser.Video} This Video object for method chaining.
253
+
* @return {Phaser.Video} This Video object for method chaining or false if the device doesn't support getUserMedia.
0 commit comments