Video ๊ฐ์ฒด ์ƒ์„ฑ, ํ•ด์ œ


์›น๊ณผ ๋ฐ์Šคํฌํƒ‘ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์—์„œ ๋™์‹œ์— ์›น์นด๋ฉ”๋ผ๋ฅผ ์‚ฌ์šฉํ•ด์•ผ ํ•˜๋Š” ๊ฒฝ์šฐ๊ฐ€ ์ƒ๊ฒผ๋‹ค. ์›น์—์„œ๋„ HTML์˜ Video Object๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ๋ฐ์Šคํฌํƒ‘ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์—์„œ๋„ HTML์˜ Video Object๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ๋•Œ๋ฌธ์— ํ•œ ๊ตฐ๋ฐ์—์„œ ์›น ์นด๋ฉ”๋ผ๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ๋Š” ๊ฒฝ์šฐ ๋‹ค๋ฅธ ๊ณณ์—์„œ ์›น ์นด๋ฉ”๋ผ ์‚ฌ์šฉ์ด ๋ถˆ๊ฐ€๋Šฅํ•˜๋‹ค. ํ”„๋กœ๊ทธ๋žจ์„ ์ข…๋ฃŒํ•ด์•ผํ•˜๋Š” ๋ฒˆ๊ฑฐ๋กœ์›€์„ ์—†์• ๊ธฐ ์œ„ํ•ด์„œ ๋ฐ์Šคํฌํƒ‘ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์—์„œ ๋น„๋””์˜ค ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑ/ ํ•ด์ œํ•˜๋Š” ๊ธฐ๋Šฅ์„ ์ถ”๊ฐ€ํ–ˆ๋‹ค. ๋‹จ์ˆœํžˆ pause()๋ฅผ ์ด์šฉํ•ด ๋น„๋””์˜ค ์ถœ๋ ฅ์„ ์ค‘์ง€ํ•˜๋ฉด ์—ฌ์ „ํžˆ ์›น์—์„  ๋ฐ์Šคํฌํƒ‘ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์—์„œ ์›น ์นด๋ฉ”๋ผ๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ๋‹ค๊ณ  ์ธ์‹ํ•˜๊ธฐ ๋•Œ๋ฌธ์— video ๊ฐ์ฒด์˜ ๋ชจ๋“  ์š”์†Œ๋ฅผ ์ •์ง€ํ•ด์•ผ ํ•œ๋‹ค.


Video ๊ฐ์ฒด ์ƒ์„ฑ

 
  this.video = document.createElement("video");
  this.video.width = 480;
  this.video.height = 360;
  this.video.autoplay = true;
  this.video.style.display = "none";

  const media = navigator.mediaDevices.getUserMedia({
    video: true,
    audio: false,
    });

  media.then((stream) => {
    this.video.srcObject = stream;
    });

createElement("video")๋ฅผ ํ˜ธ์ถœํ•ด HTML ๋น„๋””์˜ค ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•œ๋‹ค. getUserMedia()๋กœ ๋ฐ›์•„์˜จ ์‚ฌ์šฉ์ž์˜ ๋น„๋””์˜คstream๋ฅผ this.video.srcObject์— ํ• ๋‹นํ•œ๋‹ค.

Video ๊ฐ์ฒด ํ•ด์ œ


this.video.pause();
this.video.srcObject.getTracks()[0].stop();
this.video.srcObject = null;

MediaStreamTrack์˜ stop()์„ ํ˜ธ์ถœํ•˜์—ฌ ๋น„๋””์˜ค ์ŠคํŠธ๋ฆผ์„ ์ •์ง€ํ•œ๋‹ค. this.video.srcObject๋ฅผ null๋กœ ์„ค์ •ํ•˜์—ฌ ๊ฐ์ฒด๋ฅผ ํ•ด์ œํ•œ๋‹ค.


Reference