Я новичок в программировании WinJS, и завтра у меня есть этот проект. Кажется, что все работает нормально, но как только я максимизирую приложение метро (после минимизации) камера замерзает.WINJS: замораживание камеры после максимизации
Теперь я не могу найти событие «после максимизации», я попробовал onresume, активирован, обработан, oncheckpoint, но ни один из них, похоже, не вызывает его. Кроме того, я тоже не могу найти «минимизировать», поэтому я могу правильно закрыть устройство.
Заранее благодарен!
(function() {
"use strict";
var app = WinJS.Application;
var activation = Windows.ApplicationModel.Activation;
var mediaCaptureMgr;
var captureInitSettings;
var video;
var photoFile = null;
var photoStorage = null;
var currentCountdownCounter = 3;
var imgCountdown;
var isRunning = false;
var currentDate;
var imgResult;
var resolutions;
var videoDev;
var currentResolution;
function setCaptureSettings() {
captureInitSettings = null;
captureInitSettings = new Windows.Media.Capture.MediaCaptureInitializationSettings();
captureInitSettings.photoCaptureSource = Windows.Media.Capture.PhotoCaptureSource.videoPreview;
captureInitSettings.streamingCaptureMode = Windows.Media.Capture.StreamingCaptureMode.audioAndVideo;
}
function setVideoFeed() {
video = document.getElementById("camFeed");
video.addEventListener("click", countDown);
video.src = URL.createObjectURL(mediaCaptureMgr, { oneTimeOnly: true });
}
function playVideo() {
video.play();
}
function countDown() {
if (currentCountdownCounter > 0) {
isRunning = true;
imgCountdown.setAttribute("style", "margin-left: " + ((window.innerWidth/2) - 75).toString() + "px; margin-top: " + ((window.innerHeight/2) - 75).toString() + "px;");
imgCountdown.src = "/images/" + currentCountdownCounter.toString() + ".png";
currentCountdownCounter--;
WinJS.Promise.timeout(1000).then(countDown);
} else {
imgCountdown.setAttribute("style", "display: none;");
currentCountdownCounter = 3;
takePicture();
}
}
function takePicture() {
currentDate = new Date;
photoFile =
currentDate.getFullYear().toString() +
currentDate.getMonth().toString() +
currentDate.getDay().toString() +
"-" +
currentDate.getHours().toString() +
currentDate.getMinutes().toString() +
currentDate.getSeconds().toString() +
"-" +
currentDate.getMilliseconds().toString() +
".jpg";
Windows.Storage.KnownFolders.picturesLibrary.createFileAsync(photoFile, Windows.Storage.CreationCollisionOption.generateUniqueName).then(function (newFile) {
photoStorage = newFile;
var photoProperties = Windows.Media.MediaProperties.ImageEncodingProperties.createJpeg();
mediaCaptureMgr.capturePhotoToStorageFileAsync(photoProperties, photoStorage).done(function (result) {
var url = URL.createObjectURL(photoStorage, { oneTimeOnly: true });
showPicture(url);
});
});
}
function showPicture(url) {
imgResult.src = url;
imgResult.setAttribute("style", "z-index: 5;");
WinJS.Promise.timeout(10000).then(function() {
imgResult.removeAttribute("style");
});
}
function resumingHandler() {
// TODO RESUME HANDLER, RESTART CAMERA
}
app.onactivated = function (args) {
imgCountdown = document.getElementById("countDown");
imgResult = document.getElementById("result");
setCaptureSettings();
mediaCaptureMgr = new Windows.Media.Capture.MediaCapture();
mediaCaptureMgr.initializeAsync().done(function (result) {
videoDev = mediaCaptureMgr.videoDeviceController;
resolutions = mediaCaptureMgr.videoDeviceController.getAvailableMediaStreamProperties(Windows.Media.Capture.MediaStreamType.photo);
resolutions.forEach(function (data, index, array) {
if (data.height == 720 && data.width == 1280 && data.subtype == "RGB24") {
currentResolution = index;
}
});
videoDev.setMediaStreamPropertiesAsync(Windows.Media.Capture.MediaStreamType.photo, resolutions[currentResolution]);
setVideoFeed();
playVideo();
});
args.setPromise(WinJS.UI.processAll());
};
app.start();
})();