Navigate back to the homepage

Mute and Unmute functionality in mediastream react

Infinitbility
React
April 28th, 2021 · 1 min read
Mute and Unmute functionality in mediastream react

Hello Friends 👋,

Welcome To Infinitbility! ❤️

in this article, we are use RecordRTC and MediaStream to record audio.

This article provide example to add mute and unmute functionality in your react web rtc application.

Let’s start today topic how to add mute and unmute functionality in mediastream react

1let audioTrack;
2
3await navigator.mediaDevices
4 .getUserMedia({ audio: true })
5 .then((audioStream) => {
6 let track = audioStream.getAudioTracks();
7 if(track.length){
8 audioTrack = track[0];
9 }
10 let finalTrack = new MediaStream();
11 // audioStream.active = false;
12 window.RecordRTC.getTracks(audioStream, "audio").forEach((track) => {
13 finalTrack.addTrack(track);
14 });
15
16 let response = recorder = window.RecordRTC(finalTrack, {
17 type: "video",
18 mimeType: "video/webm",
19 });
20
21 }).catch((error) => {
22 console.log(error);
23 });

create audioTrack as a global veriable and store audioStream.getAudioTracks() response and use like below example.

1const handleVoice = () => {
2 if(muteAudio){
3 audioTrack.enabled = false;
4 setMuteAudio(false);
5 }else{
6 audioTrack.enabled = true;
7 setMuteAudio(true);
8 }
9}

Thanks For Reading…

Looking For React Native Tutorial?

we are trying to create the best Tutorial for react native developers.

When you want a daily updates about React Native Tutorial or infinitbility update subscribe to our newsletter.

Read React Native Tutorial

Request New Tutorial or Article on mail [email protected]

Join our email list and get notified about new content

No worries, I respect your privacy and I will never abuse your email.

Every week, on Tuesday, you will receive a list of free tutorials I made during the week (I write one every day) and news on other training products I create.

More articles from Infinitbility

Laravel exist and doesntExist query Example

Laravel exist and doesntExist query Example

how to check record exist or not in laravel

April 27th, 2021 · 1 min read
Laravel Select First Row Only

Laravel Select First Row Only

how to Select only first row in laravel

April 26th, 2021 · 1 min read
© 2020–2021 Infinitbility
Disclaimer
Link to $https://medium.com/infinitbilityLink to $https://www.facebook.com/InfinitbilityLink to $https://github.com/infinitbilityLink to $https://twitter.com/infinitbilityLink to $https://www.buymeacoffee.com/infinitbilityLink to $mailto:[email protected]