카메라 또는 마이크 설정을 조정하는 방법(HTML)

[ 이 문서는 Windows 런타임 앱을 작성하는 Windows 8.x 및 Windows Phone 8.x 개발자를 대상으로 합니다. Windows 10용으로 개발하는 경우에는 최신 설명서를 참조하세요.]

밝기, 대비, 초점(카메라) 또는 볼륨(마이크)과 같이 카메라나 마이크에 대한 다양한 설정을 조정할 수 있습니다.Windows.Media.Capture API에서는 Windows.Media.Devices.VideoDeviceController 또는 Windows.Media.Devices.AudioDeviceController 개체를 검색한 후 개체의 속성을 설정하여 이 작업을 수행합니다.

사전 요구 사항

  • JavaScript에 대해 잘 알고 있어야 합니다.
  • 사용하는 컴퓨터에 카메라가 있어야 합니다.

지침

단계 1: 비디오 또는 오디오 장치 컨트롤러 검색

Windows.Media.Capture.MediaCapture 개체에는 VideoDeviceControllerAudioDeviceController 속성이 있습니다. 이들 속성을 통해 Windows.Media.Devices.VideoDeviceController 또는 Windows.Media.Devices.AudioDeviceController 개체를 검색하여 비디오 또는 오디오 장치의 설정을 제어할 수 있습니다.

// Create the media capture object.
    var oMediaCapture = new Windows.Media.Capture.MediaCapture();
    oMediaCapture.initializeAsync();
    
// Retrieve a video device controller.
var videoDeviceController = oMediaCapture.videoDeviceController;

// Retrieve an audio device controller.
var audioDeviceController = oMediaCapture.audioDeviceController;

단계 2: 비디오 장치 컨트롤러의 속성 설정

VideoDeviceController 속성은 Windows.Media.Devices.VideoDeviceController 개체를 반환합니다. 이 개체의 각 속성(밝기, 대비 또는 포커스 등)은 MediaDeviceControlCapabilities 개체를 반환하는 Capabilities 속성이 포함된 MediaDeviceControl 개체를 반환합니다. MediaDeviceControlCapabilities 개체에는 이 카메라에서 속성이 지원되는지 여부, 속성의 최소값 및 최대값, 속성 값을 가져오거나 설정할 수 있는지 여부를 결정할 수 있는 속성과 메서드가 있습니다.

다음 예제에서는 비디오 카메라의 밝기 설정을 위한 brightnessCapabilities라는 MediaDeviceControlCapabilities 개체를 검색하고 이를 사용하여 밝기 수준을 늘립니다.

// Retrieve the brightness capabilites of the video camera
var brightnessCapabilities = videoDeviceController.brightness.capabilities; 

//
// Determine if the video camera supports adjustment of the brightness setting.
//
if (brightnessCapabilities.supported)
{
  var brightness;

  //
  // Retrieve the current brightness value.
  //

  if (videoDeviceController.brightness.tryGetValue( brightness ))
  {
    //
    // Get the minimum, maximum and step size for the brightness value. 
    // 
    var min = brightnessCapabilities.min;
    var max = brightnessCapabilities.max;
    var step = brightnessCapabilities.step;
  
    //
    // Increase the brightness value by one step as long as the new value is less than or equal to the maximum.
    //

    if( (brightness + step) <= max )
    {
       if( brightnessCapabilities.trySetValue( brightness + step ) )
       {
         // The brightness was successfully increased by one step.
       }
       else
       {
         // The brightness value couldn't be increased.
       }
    }
    else
    {
       // The brightness value is greater than the maximum.
    }
  }
  else
  {
    // The brightness value couldn't be retrieved.
  }
}
else
{
  // Setting the brightness value is not supported on this camera.
}

단계 3: 오디오 장치 컨트롤러의 속성 설정

AudioDeviceController 속성은 Windows.Media.Devices.AudioDeviceController 개체를 반환합니다. 이 개체의 속성(Muted, VolumePercent 등)을 사용하면 마이크 설정을 직접 조정할 수 있습니다.

다음 예제에서는 AudioDeviceController 개체를 사용하여 마이크를 음소거/음소거 해제하고 마이크 볼륨을 늘리는 방법을 보여 줍니다.

// Mute the microphone.
audioDeviceController.muted = true;

// Un-mute the microphone.
audioDeviceController.muted = false;

// Get the current volume setting.
var currentVolume = audioDeviceController.volumePercent;

// Increase the volume by 10 percent, if possible.
if (currentVolume <= 90) {
    audioDeviceController.volumePercent = (currentVolume + 10);
}

단계 4: 전체 예제

다음 예제에서는 비디오를 파일로 캡처할 때 카메라 및 마이크 설정을 조정하는 방법을 보여 줍니다. 이 예제의 진입점은 StartMediaCaptureSession 함수입니다. 이 함수는 캡처 세션이 시작되기 전에 비디오 카메라 밝기와 마이크 볼륨을 저장하는 SetDevices 함수를 호출합니다. 캡처 세션을 만드는 방법에 대한 예제는 빠른 시작: MediaCapture API를 사용한 비디오 캡처를 참조하세요.

//
// Initialize MediaCapture global object   
//
var oMediaCapture;

function startMediaCaptureSession() {
    oMediaCapture = new Windows.Media.Capture.MediaCapture();
    oMediaCapture.initializeAsync().then (function (result) {
        // Set the audio and video.
        setDevices();
    }, errorHandler);   
}

function setDevices()
{
      
     //
     // Obtain Video and Audio device controllers. 
     //
     var videoDeviceController = oMediaCapture.videoDeviceController;
     var audioDeviceController = oMediaCapture.audioDeviceController;

     //
     // Adjust Video and Audio device settings. 
     //

     //
     // Increase the brightness value by one step as long as the new value is less than or equal to the maximum.
     //
     var brightness;
     var brightnessCapabilities = videoDeviceController.brightness.capabilities;

     brightness = videoDeviceController.brightness.tryGetValue();
               
     if( (brightness.value + brightnessCapabilities.step) <= brightnessCapabilities.max )
     {
         if (videoDeviceController.brightness.trySetValue(brightness + brightnessCapabilities.step))
         {
             // The brightness value was successfully increased by one step.             
         }
         else
         {
             // The brightness value could not be increased.             
         }
     }
     else
     {
         // The new brightness value would be greater than the maximum value.        
     }
           

     //
     // Increase the microphone volume by 10 percent if possible.
     //
     var increase = 10;
     var currentVolume = audioDeviceController.volumePercent;
     if (currentVolume + increase <= 100) {
         audioDeviceController.volumePercent += increase;
     }
}

설명

Windows.Media.Capture.CameraOptionsUI.Show를 호출하고 MediaCapture 개체를 매개 변수로 전달하여 카메라 설정을 조정하는 대화 상자를 시작할 수도 있습니다.