From 9c906b2ab7e7bee031abd85be13910a2a67754ca Mon Sep 17 00:00:00 2001 From: Raghav Katyal Date: Wed, 2 Mar 2016 14:15:01 -0800 Subject: [PATCH] CB-10414: Adding focus handler to resume video when user comes back on leaving the app while preview was running --- src/windows/CameraProxy.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/windows/CameraProxy.js b/src/windows/CameraProxy.js index 0eb7d3d..e0be5b8 100644 --- a/src/windows/CameraProxy.js +++ b/src/windows/CameraProxy.js @@ -351,12 +351,22 @@ function takePictureFromCameraWP(successCallback, errorCallback, args) { captureSettings.streamingCaptureMode = CaptureNS.StreamingCaptureMode.video; } + function continueVideoOnFocus() { + // if preview is defined it would be stuck, play it + if (capturePreview) { + capturePreview.play(); + } + } + function startCameraPreview() { // Search for available camera devices // This is necessary to detect which camera (front or back) we should use var DeviceEnum = Windows.Devices.Enumeration; var expectedPanel = cameraDirection === 1 ? DeviceEnum.Panel.front : DeviceEnum.Panel.back; + // Add focus event handler to capture the event when user suspends the app and comes back while the preview is on + window.addEventListener("focus", continueVideoOnFocus); + DeviceEnum.DeviceInformation.findAllAsync(DeviceEnum.DeviceClass.videoCapture).then(function (devices) { if (devices.length <= 0) { destroyCameraPreview(); @@ -459,6 +469,9 @@ function takePictureFromCameraWP(successCallback, errorCallback, args) { cameraCaptureButton.removeEventListener('click', onCameraCaptureButtonClick); cameraCancelButton.removeEventListener('click', onCameraCancelButtonClick); + // Remove the focus event handler + window.removeEventListener("focus", continueVideoOnFocus); + // Remove elements [capturePreview, cameraCaptureButton, cameraCancelButton].forEach(function (elem) { if (elem /* && elem in document.body.childNodes */) {