Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update camera.js #1239

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 20 additions & 11 deletions archived/CameraStarterKit/js/js/camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@
return oMediaCapture.initializeAsync(settings)
.then(function () {
isInitialized = true;
startPreview();
// Get all available media stream properties and select the first one as default
var allProperties = oMediaCapture.videoDeviceController.getAvailableMediaStreamProperties(Capture.MediaStreamType.videoPreview);
startPreview(oMediaCapture, Capture.MediaStreamType.videoPreview, allProperties[0]);
});
}, function (error) {
console.log(error.message);
Expand Down Expand Up @@ -207,9 +209,10 @@
}

/// <summary>
/// Sets encoding properties on a camera stream. Ensures VideoElement and preview stream are stopped before setting properties.
/// Starts the preview and adjusts it for for rotation and mirroring after making a request to keep the screen on
/// </summary>
function startPreview() {
function startPreview(mediaCapture, streamType, encodingProperties) {
// Prevent the device from sleeping while the preview is running
oDisplayRequest.requestActive();

Expand All @@ -219,15 +222,21 @@
cameraPreview.style.transform = "scale(-1, 1)";
}

var previewUrl = URL.createObjectURL(oMediaCapture);
previewVidTag.src = previewUrl;
previewVidTag.play();

previewVidTag.addEventListener("playing", function () {
isPreviewing = true;
updateCaptureControls();
setPreviewRotationAsync();
});
// Apply desired stream properties
return mediaCapture.videoDeviceController.setMediaStreamPropertiesAsync(streamType, encodingProperties)
.then(function () {
// Recreate pipeline and restart the preview
previewVidTag = document.getElementById("cameraPreview");
var previewUrl = URL.createObjectURL(mediaCapture);
previewVidTag.src = previewUrl;
previewVidTag.play();

previewVidTag.addEventListener("playing", function () {
isPreviewing = true;
updateCaptureControls();
setPreviewRotationAsync();
});
});
}

/// <summary>
Expand Down