问题
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)
回答1:
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.
来源:https://stackoverflow.com/questions/56944864/can-we-remove-and-add-audio-stream-dynamically-in-webrtc-video-call-without-rene