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 I can enable/disable the microphone/camera without restarting the stream? #7

Open
kolik29 opened this issue Apr 13, 2022 · 1 comment

Comments

@kolik29
Copy link

kolik29 commented Apr 13, 2022

Hello! In example https://demo.ovenplayer.com/demo_input.html I can change audio settings and select "Without audio", but then streaming stopped. I can disable the microphone without stopping the stream?

@kolik29 kolik29 changed the title How I can enable/disable the microphone/camera without restarting the stream How I can enable/disable the microphone/camera without restarting the stream? Apr 13, 2022
@bchah
Copy link

bchah commented Apr 14, 2022

I don't think the demo page does it, but here is what I do in my app. After calling OvenLiveKit.getUserMedia(constraints), you can enable / disable the video or audio track like so:

                let videoTrack = userMedia.getVideoTracks()[0];
                let audioTrack = userMedia.getAudioTracks()[0];

                $("#muteOwnVideo, #muteOwnAudio").off("click");

                $("#muteOwnVideo").on("click", () => {
                    let enabled = videoTrack.enabled;
                    videoTrack.enabled = !enabled;
                    let src = enabled ? "./img/icons/camera_off.svg" : "./img/icons/camera_on.svg";
                    $("#muteOwnVideo").attr("src", src);
                });

                $("#muteOwnAudio").on("click", () => {
                    let enabled = audioTrack.enabled;
                    audioTrack.enabled = !enabled;
                    let src = enabled ? "./img/icons/mic_muted.svg" : "./img/icons/mic_unmuted.svg";
                    $("#muteOwnAudio").attr("src", src);
                });

Obviously some of this is specific to my app but if you are using JS on the front end feel free to use this as a guiding point.

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

No branches or pull requests

2 participants