使用后置摄像头代替前置摄像头

时间:2014-05-14 15:37:01

标签: camera winjs windows-phone-8.1 win-universal-app

如何强制Capture管理器使用后置摄像头,因为我无法在Windows Phone 8.1中使用CameraCaptureUI。

该应用程序启动默认前置摄像头。

这是我的代码:

function initCaptureSettings() {
    captureInitSettings = null;
    captureInitSettings =
        new Windows.Media.Capture.MediaCaptureInitializationSettings();
    captureInitSettings.photoCaptureSource = Windows.Media.Capture.PhotoCaptureSource.photo;
    captureInitSettings.streamingCaptureMode =
        Windows.Media.Capture.StreamingCaptureMode.audioAndVideo;
    startDevice();
}


function startDevice() {
    Debug.writeln("Starting device");
    releaseMediaCapture();
    mediaCaptureMgr = new Windows.Media.Capture.MediaCapture();
    mediaCaptureMgr.initializeAsync(captureInitSettings).done(function (result) {

        // do we have a camera and a microphone present?
        if (mediaCaptureMgr.mediaCaptureSettings.videoDeviceId && mediaCaptureMgr.mediaCaptureSettings.audioDeviceId) {

            // Update the UI
            Debug.writeln("Device started");


        } else {
            Debug.writeln("No capture device was found");

        }
        startPreview();
    }, errorHandler);
}

function startPreview() {
    Debug.writeln("Starting preview");

    try {
        var video = id("photoCapture");
        //Windows.Media.Capture.CameraOptionsUI.show(mediaCaptureMgr);
        video.src = URL.createObjectURL(mediaCaptureMgr, { oneTimeOnly: true });
        video.play();

    } catch (e) {
        Debug.writeln("Preview failed: " + e.message);
        return;
    }

    Debug.writeln("Preview started");
    intervalID = setInterval(function () {
        capturePhoto();
    }, 1500);
}

我想这是设置中的内容。

1 个答案:

答案 0 :(得分:0)

试试这个

var devices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);

await mediaCaptureMgr.InitializeAsync(new MediaCaptureInitializationSettings
{
      VideoDeviceId = devices[1].Id
});