[英]Is there a way to keep the websocket open in windows phone 8.1 app running in the background?
[英]Can't access the camera from the app on Lumia 520 (running Windows Phone 8.1 Preview)
我是WP开发人员的初学者,正在学习如何编写简单的录像机应用程序。 我在VS Pro 2013上使用javascript和HTML,并在实际设备Lumia 520(运行Windows Phone 8.1预览版)上进行调试。 我通读了大量文档,发现MediaCapture类是用于此目的的核心类。 因此,我开始遵循一些教程,并编写了一些功能来访问摄像机并在HTML5视频标签中显示预览。 但是,我没有成功初始化MediaCapture对象,甚至没有显示预览。 以下是第一个有问题的主要功能:
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;
}
在调试期间,我在语句oMediaCapture = new Windows.Media.Capture.MediaCapture();
处暂停了一下oMediaCapture = new Windows.Media.Capture.MediaCapture();
在initCapture()
函数中。 此时, captureInitSettings.videoDeviceId
的值为:“ \\\\?\\ DISPLAY#QCOM_AVStream#3&25691128&0&UID32768#{e5323777-f976-4f5b-9b55-b94699c46e44} \\ Back Sensor”,我认为这是对后置摄像头的正确识别我打算用。 然后,当我继续在var preview = document.getElementById("PreviewScreen");
处设置断点时var preview = document.getElementById("PreviewScreen");
在应该成功初始化MediaCapture对象时调用的函数preview()
,该程序被捕获到errorHandler()
函数中,错误消息为“访问被拒绝”,错误号为“ -2147024891”。 因此,我想问题出在.initializeAsync()
函数上,但没有成功。 更深层次的原因还可能与访问相机的权限有关。 顺便说一句,我已经为此应用程序启用了网络摄像头和麦克风功能,这不是问题。
我相信我在代码中或开发设置的全局图中都缺少一些东西。 请帮助我确定问题,并让我知道是否需要其他信息。 非常感激!
您确定在包装清单中添加了后置摄像头要求吗?
原来问题出在我的设备上。 回想一下,我在带有Windows Phone 8.1预览版的Lumia 520上进行了测试,固件保持在Lumia Black。 使用诺基亚恢复软件工具将固件升级到Lumia Cyan(与Windows Phone 8.1平行)后,问题消失了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.