diff --git a/src/main/java/eu/siacs/conversations/ui/RtpSessionActivity.java b/src/main/java/eu/siacs/conversations/ui/RtpSessionActivity.java index 5db8dfc6d99938d80842570ff7857a48bbbb96f4..9bff9ff988bdf3d3a4982551fe8e4fdad88b75a4 100644 --- a/src/main/java/eu/siacs/conversations/ui/RtpSessionActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/RtpSessionActivity.java @@ -910,15 +910,17 @@ public class RtpSessionActivity extends XmppActivity implements XmppConnectionSe } private void disableMicrophone(View view) { - JingleRtpConnection rtpConnection = requireRtpConnection(); - rtpConnection.setMicrophoneEnabled(false); - updateInCallButtonConfiguration(); + final JingleRtpConnection rtpConnection = requireRtpConnection(); + if (rtpConnection.setMicrophoneEnabled(false)) { + updateInCallButtonConfiguration(); + } } private void enableMicrophone(View view) { - JingleRtpConnection rtpConnection = requireRtpConnection(); - rtpConnection.setMicrophoneEnabled(true); - updateInCallButtonConfiguration(); + final JingleRtpConnection rtpConnection = requireRtpConnection(); + if (rtpConnection.setMicrophoneEnabled(true)) { + updateInCallButtonConfiguration(); + } } private void switchToEarpiece(View view) { diff --git a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleRtpConnection.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleRtpConnection.java index 28f7c738bc980f6fcc75fa0e3afba907617e0eff..830695831e6defbbd6f3ada285e68c6bb2d96ea5 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleRtpConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleRtpConnection.java @@ -1085,8 +1085,8 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web return webRTCWrapper.isMicrophoneEnabled(); } - public void setMicrophoneEnabled(final boolean enabled) { - webRTCWrapper.setMicrophoneEnabled(enabled); + public boolean setMicrophoneEnabled(final boolean enabled) { + return webRTCWrapper.setMicrophoneEnabled(enabled); } public boolean isVideoEnabled() { diff --git a/src/main/java/eu/siacs/conversations/xmpp/jingle/WebRTCWrapper.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/WebRTCWrapper.java index ff7e6a6771410cb8e34e5078848eb92a4ef9f907..98ce37a4e558eeb8da41c27e29a71a94a8d73cb4 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/WebRTCWrapper.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/WebRTCWrapper.java @@ -370,12 +370,19 @@ public class WebRTCWrapper { } } - void setMicrophoneEnabled(final boolean enabled) { + boolean setMicrophoneEnabled(final boolean enabled) { final AudioTrack audioTrack = this.localAudioTrack; if (audioTrack == null) { throw new IllegalStateException("Local audio track does not exist (yet)"); } - audioTrack.setEnabled(enabled); + try { + audioTrack.setEnabled(enabled); + return true; + } catch (final IllegalStateException e) { + Log.d(Config.LOGTAG, "unable to toggle microphone", e); + //ignoring race condition in case MediaStreamTrack has been disposed + return false; + } } boolean isVideoEnabled() {