简体   繁体   中英

Can't access the camera from the app on Lumia 520 (running Windows Phone 8.1 Preview)

I am a WP dev beginner and learning how to write a simple video recorder app. I am using javascript and HTML on VS Pro 2013 and debugging on my actual device Lumia 520 (running Windows Phone 8.1 Preview). I read through a body of documentations and found that the MediaCapture class was the core class for this purpose. So I started following some tutorials and wrote up some functions to access the camera and display a preview in a HTML5 video tag. However, I wasn't successful in getting the MediaCapture object initialized, not even displaying the preview. Below are the major functions of which the first one was problematic:

function initCapture() {
    findRearFacingCamera().then(function (cameraId) {
        try {
            if (cameraId != null && cameraId != "") {

                // Initialize the settings
                captureInitSettings = null;
                captureInitSettings = new Windows.Media.Capture.MediaCaptureInitializationSettings();
                captureInitSettings.videoDeviceId = cameraId;
                captureInitSettings.streamingCaptureMode = Windows.Media.Capture.StreamingCaptureMode.video;
                captureInitSettings.photoCaptureSource = Windows.Media.Capture.PhotoCaptureSource.videoPreview;
                captureInitSettings.realTimeModeEnabled = true;

                // Initialize the capture
                oMediaCapture = null;
                oMediaCapture = new Windows.Media.Capture.MediaCapture();
                oMediaCapture.initializeAsync(captureInitSettings).then(preview, errorHandler);
            }
        } catch (e) { }
    });
}

function preview() {
    var preview = document.getElementById("PreviewScreen");
    preview.msZoom = true;
    if (preview != null) {
        preview.src = URL.createObjectURL(oMediaCapture);
        preview.play();
    }
}

function errorHandler(e) {
    var information = document.getElementById("message");
    information.innerHTML = e.message;
}

During debugging, I paused at the statement oMediaCapture = new Windows.Media.Capture.MediaCapture(); in the initCapture() function. At this point, captureInitSettings.videoDeviceId has the value: "\\\\?\\DISPLAY#QCOM_AVStream#3&25691128&0&UID32768#{e5323777-f976-4f5b-9b55-b94699c46e44}\\Back Sensor", which I believed was a correct identification of the rear camera that I intended to use. Then, when I continued with a break point set at var preview = document.getElementById("PreviewScreen"); in function preview() , which was supposed to be called upon successful initialization of the MediaCapture object, the program was trapped into the errorHandler() function instead, with the error message being "Access is denied" with error number "-2147024891". So I guess the problem rose from the .initializeAsync() function, which was unsuccessful. Deeper causes might also be related to the permission to access the camera. BTW, I have enabled the webcam and microphone capabilities for this app, which was not the issue.

I believe I was missing something either in the code or in the big picture of the development settings. Please help me identify the issue and let me know if any additional information is needed. Much appreciated!

您确定在包装清单中添加了后置摄像头要求吗?

Turned out the problem was really with my device. Recall that I was testing on a Lumia 520 with Windows Phone 8.1 preview, the firmware stayed at Lumia Black. After upgrading the firmware to Lumia Cyan (parallel to Windows Phone 8.1) using the Nokia Recovery Software Tool , the problem disappeared.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM