Alex Chengalan
Alex Chengalan

Reputation: 8281

Switch between Audio and Video call in appRTC Android code

I integrated appRTC code in my Android application for calling purpose, which is done. Now the Video & Audio calling is working fine. My problem is, I need to achieve following things.

1. Mute & Unmute Audio while calling.

2. Switch Video call to Audio Call and vise versa while calling.

I have searched a lot and had no luck so far. It would be nice if you can give me any lead on these things. Thanks in advance.

Upvotes: 0

Views: 2926

Answers (4)

Medo Zeus
Medo Zeus

Reputation: 99

use this for switch between mute -> unMute, Video -> Audio

just need the MediaStream localMS

    //disable video in stream
    VideoTrack currentTrack = localMS.videoTracks.get(0);
    currentTrack.setEnabled(false);

    //disable audio in stream // mute
    AudioTrack curentAudioTrack = localMS.audioTracks.get(0);
    curentAudioTrack.setEnabled(false);

if you want to unMute just use true like this

    AudioTrack curentAudioTrack = localMS.audioTracks.get(0);
    curentAudioTrack.setEnabled(true);

same for video

Upvotes: 0

Ashish singh
Ashish singh

Reputation: 351

Please refer to this Link for switching audio / Video - Link

although this is in javascript but it can be easily implemented in android.

when the connection is created via webrtc we receive Media Stream ,for switching purpose we can remove audiotrack or videotrack and then again send sdp from offerer to answerer side with new configuration.

mediaStream.removeAudioTrack(Audiotrack audioTrack) ; //for audio to video switching

mediaStream.removeVideoTrack(VideoTrack videoTrack) ; // video to audio switching

Upvotes: 0

Alex Chengalan
Alex Chengalan

Reputation: 8281

So far no luck about switching between Audio and Video Call. But I have found a solution to mute microphone audio while calling. There is a setMicrophoneMute(boolean on) method in AppRTCAudioManager. We can use the same code to mute the microphone. I just created another method like this.

public void setMicroPhoneMute(){
    boolean wasMuted = audioManager.isMicrophoneMute();
    if(wasMuted)
        audioManager.setMicrophoneMute(false);
    else
        audioManager.setMicrophoneMute(true);
}

Just call this one wherever you want.

Upvotes: 1

ssk
ssk

Reputation: 9255

1. Mute & Unmute Audio while calling.

This class is used to control the audio: https://chromium.googlesource.com/external/webrtc/+/b69ab79338bff71ea411b82f3dd59508617a11d5/talk/examples/android/src/org/appspot/apprtc/AppRTCAudioManager.java

You may need to explicitly add mute functionality here.

2. Switch Video call to Audio Call and vise versa while calling.

PeerConnectionClient class in AppRtc demo depends on the following class:

https://chromium.googlesource.com/external/webrtc/+/b69ab79338bff71ea411b82f3dd59508617a11d5/talk/app/webrtc/java/src/org/webrtc/VideoCapturerAndroid.java

To switch video call to audio, you need to explicitly call stopCapture in VideoCapturerAndroid.java

Upvotes: 3

Related Questions