From 71333765c9fb2fd08c84b61359d6346847881754 Mon Sep 17 00:00:00 2001 From: Paul Kaplan Date: Fri, 13 Apr 2018 10:19:38 -0400 Subject: [PATCH 1/3] Use new mediaDevices API for getUserMedia --- src/io/video.js | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/io/video.js b/src/io/video.js index 6c72be885..5937466f6 100644 --- a/src/io/video.js +++ b/src/io/video.js @@ -240,23 +240,28 @@ class Video { return this._singleSetup; } - this._singleSetup = new Promise((resolve, reject) => { - navigator.getUserMedia({ - audio: false, - video: { - width: {min: 480, ideal: 640}, - height: {min: 360, ideal: 480} - } - }, resolve, reject); + this._singleSetup = navigator.mediaDevices.getUserMedia({ + audio: false, + video: { + width: {min: 480, ideal: 640}, + height: {min: 360, ideal: 480} + } }) .then(stream => { 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); + } + this._video.play(); // 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 // hide the video tag and instead render a sample of the stream into // the webgl rendered Scratch canvas, another hint like this one is // needed. + this._video.play(); // Needed for Safari/Firefox, Chrome auto-plays. this._track = stream.getTracks()[0]; this._setupPreview(); return this; From c46d1157faf01c4a63d2b7b529a45bbe7ba07027 Mon Sep 17 00:00:00 2001 From: Paul Kaplan Date: Fri, 13 Apr 2018 10:20:00 -0400 Subject: [PATCH 2/3] Slicing array buffers with no args throws on Safari --- src/extensions/scratch3_video_sensing/library.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/extensions/scratch3_video_sensing/library.js b/src/extensions/scratch3_video_sensing/library.js index 51a7deef5..04abc20ea 100644 --- a/src/extensions/scratch3_video_sensing/library.js +++ b/src/extensions/scratch3_video_sensing/library.js @@ -162,7 +162,7 @@ class VideoMotion { this.prev = this.curr; // Create a clone of the array so any modifications made to the source // 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 // array into _curr overwriting what was the old _prev data. From 0838f6c875a4ed60ea40b7818cfb44a06742f306 Mon Sep 17 00:00:00 2001 From: Paul Kaplan Date: Fri, 13 Apr 2018 11:12:44 -0400 Subject: [PATCH 3/3] Remove duplicate play --- src/io/video.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/io/video.js b/src/io/video.js index 5937466f6..ba05ff244 100644 --- a/src/io/video.js +++ b/src/io/video.js @@ -255,7 +255,6 @@ class Video { } catch (error) { this._video.src = window.URL.createObjectURL(stream); } - this._video.play(); // 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 // hide the video tag and instead render a sample of the stream into