saneesh
saneesh

Reputation: 169

can we remove and add audio stream dynamically in webRTC video call without renegotiation

I am doing a webRTC videoCall application . At apoint I need a voice record ( Normal), So I just removed the audio track from peerconnection and after record I need to add audio track to peerconnection . But i cann't do it !!

 public void removeAudioTrack() {

        List<RtpSender> senders = new ArrayList<>();
        senders.addAll(peerConnection.getSenders());

        try {
            for (RtpSender sender : senders) {
                if (sender.track() != null) {
                    if (sender.track().id().equals(AUDIO_TRACK_ID)) {
                        boolean flag = peerConnection.removeTrack(sender);
                        rtpSender = sender;                       
                    }

                }
            }
        } catch (Exception e) {

        }
}


 public void addAudioTrack() {

        localAudioTrack = createAudioTrack();
        mediaStream.addTrack(localAudioTrack);
        audioSender = peerConnection.addTrack(localAudioTrack,mediaStreamLabels);

}

The audio voice not getting in another side (error)

Upvotes: 2

Views: 1490

Answers (1)

Pallab Gain
Pallab Gain

Reputation: 336

As per the webrtc-pc standard - You cannot remove or add stream dynamically without re-negotiation. However, you can replace track to replace the current RTCPSender track with another track. And as per webrtc-pc standard this doesn't require a re-negotiation.

Upvotes: 2

Related Questions