Skip to content

Commit 0057478

Browse files
committed
videoUploading: add webcam as a source video option
1 parent 3b3f53e commit 0057478

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

‎sample/videoUploading/main.ts‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ const videos = {
2020
url: '../../assets/video/Video_360°._Timelapse._Bled_Lake_in_Slovenia..webm.720p.vp9.webm',
2121
mode: '360',
2222
},
23+
webcam: {
24+
url: '',
25+
mode: 'mirror',
26+
},
2327
} as const;
2428

2529
const canvas = document.querySelector('canvas') as HTMLCanvasElement;
@@ -90,7 +94,21 @@ let canReadVideo = false;
9094

9195
async function playVideo(videoName: keyof typeof videos) {
9296
canReadVideo = false;
93-
video.src = videos[videoName].url;
97+
98+
if (video.srcObject) {
99+
(video.srcObject as MediaStream)
100+
.getTracks()
101+
.forEach((track) => track.stop());
102+
video.srcObject = null;
103+
}
104+
105+
if (videoName === 'webcam') {
106+
video.srcObject = await navigator.mediaDevices.getUserMedia({
107+
video: true,
108+
});
109+
} else {
110+
video.src = videos[videoName].url;
111+
}
94112
await video.play();
95113
canReadVideo = true;
96114
}
@@ -182,6 +200,9 @@ function drawVideo() {
182200
combinedAspect > 1 ? [1 / combinedAspect, 1] : [1, combinedAspect],
183201
mat
184202
);
203+
if (mode === 'mirror') {
204+
mat3.scale(mat, [-1, 1], mat);
205+
}
185206
mat3.translate(mat, [-0.5, -0.5], mat);
186207
device.queue.writeBuffer(uniformBuffer, 0, mat);
187208
}

0 commit comments

Comments
 (0)