mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-24 06:52:40 -05:00
Merge pull request #1058 from paulkaplan/fix-gum
Fix video motion in Safari/Firefox
This commit is contained in:
commit
651fb58abc
2 changed files with 14 additions and 10 deletions
|
@ -162,7 +162,7 @@ class VideoMotion {
|
||||||
this.prev = this.curr;
|
this.prev = this.curr;
|
||||||
// Create a clone of the array so any modifications made to the source
|
// Create a clone of the array so any modifications made to the source
|
||||||
// array do not affect the work done in here.
|
// array do not affect the work done in here.
|
||||||
this.curr = new Uint32Array(source.buffer.slice());
|
this.curr = new Uint32Array(source.buffer.slice(0));
|
||||||
|
|
||||||
// Swap _prev and _curr. Copy one of the color components of the new
|
// Swap _prev and _curr. Copy one of the color components of the new
|
||||||
// array into _curr overwriting what was the old _prev data.
|
// array into _curr overwriting what was the old _prev data.
|
||||||
|
|
|
@ -240,23 +240,27 @@ class Video {
|
||||||
return this._singleSetup;
|
return this._singleSetup;
|
||||||
}
|
}
|
||||||
|
|
||||||
this._singleSetup = new Promise((resolve, reject) => {
|
this._singleSetup = navigator.mediaDevices.getUserMedia({
|
||||||
navigator.getUserMedia({
|
audio: false,
|
||||||
audio: false,
|
video: {
|
||||||
video: {
|
width: {min: 480, ideal: 640},
|
||||||
width: {min: 480, ideal: 640},
|
height: {min: 360, ideal: 480}
|
||||||
height: {min: 360, ideal: 480}
|
}
|
||||||
}
|
|
||||||
}, resolve, reject);
|
|
||||||
})
|
})
|
||||||
.then(stream => {
|
.then(stream => {
|
||||||
this._video = document.createElement('video');
|
this._video = document.createElement('video');
|
||||||
this._video.src = window.URL.createObjectURL(stream);
|
// Use the new srcObject API, falling back to createObjectURL
|
||||||
|
try {
|
||||||
|
this._video.srcObject = stream;
|
||||||
|
} catch (error) {
|
||||||
|
this._video.src = window.URL.createObjectURL(stream);
|
||||||
|
}
|
||||||
// Hint to the stream that it should load. A standard way to do this
|
// Hint to the stream that it should load. A standard way to do this
|
||||||
// is add the video tag to the DOM. Since this extension wants to
|
// is add the video tag to the DOM. Since this extension wants to
|
||||||
// hide the video tag and instead render a sample of the stream into
|
// hide the video tag and instead render a sample of the stream into
|
||||||
// the webgl rendered Scratch canvas, another hint like this one is
|
// the webgl rendered Scratch canvas, another hint like this one is
|
||||||
// needed.
|
// needed.
|
||||||
|
this._video.play(); // Needed for Safari/Firefox, Chrome auto-plays.
|
||||||
this._track = stream.getTracks()[0];
|
this._track = stream.getTracks()[0];
|
||||||
this._setupPreview();
|
this._setupPreview();
|
||||||
return this;
|
return this;
|
||||||
|
|
Loading…
Reference in a new issue