CB-10414: Adding focus handler to resume video when user comes back on leaving the app while preview was running
This commit is contained in:
parent
56b9469313
commit
9c906b2ab7
@ -351,12 +351,22 @@ function takePictureFromCameraWP(successCallback, errorCallback, args) {
|
|||||||
captureSettings.streamingCaptureMode = CaptureNS.StreamingCaptureMode.video;
|
captureSettings.streamingCaptureMode = CaptureNS.StreamingCaptureMode.video;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function continueVideoOnFocus() {
|
||||||
|
// if preview is defined it would be stuck, play it
|
||||||
|
if (capturePreview) {
|
||||||
|
capturePreview.play();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function startCameraPreview() {
|
function startCameraPreview() {
|
||||||
// Search for available camera devices
|
// Search for available camera devices
|
||||||
// This is necessary to detect which camera (front or back) we should use
|
// This is necessary to detect which camera (front or back) we should use
|
||||||
var DeviceEnum = Windows.Devices.Enumeration;
|
var DeviceEnum = Windows.Devices.Enumeration;
|
||||||
var expectedPanel = cameraDirection === 1 ? DeviceEnum.Panel.front : DeviceEnum.Panel.back;
|
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) {
|
DeviceEnum.DeviceInformation.findAllAsync(DeviceEnum.DeviceClass.videoCapture).then(function (devices) {
|
||||||
if (devices.length <= 0) {
|
if (devices.length <= 0) {
|
||||||
destroyCameraPreview();
|
destroyCameraPreview();
|
||||||
@ -459,6 +469,9 @@ function takePictureFromCameraWP(successCallback, errorCallback, args) {
|
|||||||
cameraCaptureButton.removeEventListener('click', onCameraCaptureButtonClick);
|
cameraCaptureButton.removeEventListener('click', onCameraCaptureButtonClick);
|
||||||
cameraCancelButton.removeEventListener('click', onCameraCancelButtonClick);
|
cameraCancelButton.removeEventListener('click', onCameraCancelButtonClick);
|
||||||
|
|
||||||
|
// Remove the focus event handler
|
||||||
|
window.removeEventListener("focus", continueVideoOnFocus);
|
||||||
|
|
||||||
// Remove elements
|
// Remove elements
|
||||||
[capturePreview, cameraCaptureButton, cameraCancelButton].forEach(function (elem) {
|
[capturePreview, cameraCaptureButton, cameraCancelButton].forEach(function (elem) {
|
||||||
if (elem /* && elem in document.body.childNodes */) {
|
if (elem /* && elem in document.body.childNodes */) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user