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

How to use a webcam/camera? #3927

Open
2 tasks done
JaneX8 opened this issue Dec 2, 2024 · 1 comment
Open
2 tasks done

How to use a webcam/camera? #3927

JaneX8 opened this issue Dec 2, 2024 · 1 comment
Labels
Documentation Improvements or additions to documentation

Comments

@JaneX8
Copy link

JaneX8 commented Dec 2, 2024

Have you read the Documentation Contribution Guidelines?

Description

Only barely mentioned here:

How to use the webcam/camera feed in a Wails app?

Self-service

  • I'd be willing to address this documentation request myself.
@JaneX8 JaneX8 added the Documentation Improvements or additions to documentation label Dec 2, 2024
@hughie21
Copy link

hughie21 commented Dec 4, 2024

Hi, how about using navigator.mediaDevices, a front-end API, this works on the Wails app.

A simple exmple like:

function handleMediaStream(MediaStream) {
    console.log('MediaStream Object:', MediaStream)
    const video = document.createElement('video');
    video.controls = true;
    video.srcObject = MediaStream;
    video.onloadedmetadata = function () {
        video.play();
    };
    var container = document.getElementById('videoContainer');
    container.appendChild(video);
};

function getUserMedia() {
    try {
        const options = {
            audio: true, 
            video: true,
        }
        if (navigator.mediaDevices.getUserMedia) {
            navigator.mediaDevices.getUserMedia(options).then(function (MediaStream) {
                handleMediaStream(MediaStream)
            }).catch(function (err) {
                console.error(err);

            })
        }
        else if (navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia) {
            try {
                navigator.getUserMedia(options, function (MediaStream) {
                    handleMediaStream(MediaStream)
                }, function (err) {
                    console.error(err);
                })
            } catch (error) {
                console.error(err);
            }
        } else {
            console.error("Your browser does not support getUserMedia API");
        }
    } catch (error) {
        console.error(error);
    }
};
getUserMedia();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants