diff --git a/webrtc/examples/androidapp/res/layout/fragment_call.xml b/webrtc/examples/androidapp/res/layout/fragment_call.xml
index 5d71d73f50..e6d660acab 100644
--- a/webrtc/examples/androidapp/res/layout/fragment_call.xml
+++ b/webrtc/examples/androidapp/res/layout/fragment_call.xml
@@ -47,6 +47,14 @@
android:contentDescription="@string/disconnect_call"
android:layout_width="48dp"
android:layout_height="48dp"/>
+
+
OK
Switch front/back camera
Toggle debug view
+ Toggle microphone on/off
Settings
Add new room to the list
Remove room from the list
diff --git a/webrtc/examples/androidapp/src/org/appspot/apprtc/CallActivity.java b/webrtc/examples/androidapp/src/org/appspot/apprtc/CallActivity.java
index 239988a97d..21092227cc 100644
--- a/webrtc/examples/androidapp/src/org/appspot/apprtc/CallActivity.java
+++ b/webrtc/examples/androidapp/src/org/appspot/apprtc/CallActivity.java
@@ -132,6 +132,7 @@ public class CallActivity extends Activity
private boolean isError;
private boolean callControlFragmentVisible = true;
private long callStartedTimeMs = 0;
+ private boolean micEnabled = true;
// Controls
private CallFragment callFragment;
@@ -337,6 +338,15 @@ public class CallActivity extends Activity
}
}
+ @Override
+ public boolean onToggleMic() {
+ if (peerConnectionClient != null) {
+ micEnabled = !micEnabled;
+ peerConnectionClient.setAudioEnabled(micEnabled);
+ }
+ return micEnabled;
+ }
+
// Helper functions.
private void toggleCallControlFragmentVisibility() {
if (!iceConnected || !callFragment.isAdded()) {
diff --git a/webrtc/examples/androidapp/src/org/appspot/apprtc/CallFragment.java b/webrtc/examples/androidapp/src/org/appspot/apprtc/CallFragment.java
index 04b563949d..6523ffa443 100644
--- a/webrtc/examples/androidapp/src/org/appspot/apprtc/CallFragment.java
+++ b/webrtc/examples/androidapp/src/org/appspot/apprtc/CallFragment.java
@@ -31,6 +31,7 @@ public class CallFragment extends Fragment {
private ImageButton disconnectButton;
private ImageButton cameraSwitchButton;
private ImageButton videoScalingButton;
+ private ImageButton toggleMuteButton;
private TextView captureFormatText;
private SeekBar captureFormatSlider;
private OnCallEvents callEvents;
@@ -45,6 +46,7 @@ public class CallFragment extends Fragment {
public void onCameraSwitch();
public void onVideoScalingSwitch(ScalingType scalingType);
public void onCaptureFormatChange(int width, int height, int framerate);
+ public boolean onToggleMic();
}
@Override
@@ -62,6 +64,8 @@ public class CallFragment extends Fragment {
(ImageButton) controlView.findViewById(R.id.button_call_switch_camera);
videoScalingButton =
(ImageButton) controlView.findViewById(R.id.button_call_scaling_mode);
+ toggleMuteButton =
+ (ImageButton) controlView.findViewById(R.id.button_call_toggle_mic);
captureFormatText =
(TextView) controlView.findViewById(R.id.capture_format_text_call);
captureFormatSlider =
@@ -99,6 +103,14 @@ public class CallFragment extends Fragment {
});
scalingType = ScalingType.SCALE_ASPECT_FILL;
+ toggleMuteButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ boolean enabled = callEvents.onToggleMic();
+ toggleMuteButton.setAlpha(enabled ? 1.0f : 0.3f);
+ }
+ });
+
return controlView;
}
diff --git a/webrtc/examples/androidapp/src/org/appspot/apprtc/PeerConnectionClient.java b/webrtc/examples/androidapp/src/org/appspot/apprtc/PeerConnectionClient.java
index 69172c33a1..9c33b6159a 100644
--- a/webrtc/examples/androidapp/src/org/appspot/apprtc/PeerConnectionClient.java
+++ b/webrtc/examples/androidapp/src/org/appspot/apprtc/PeerConnectionClient.java
@@ -17,6 +17,7 @@ import android.util.Log;
import org.appspot.apprtc.AppRTCClient.SignalingParameters;
import org.appspot.apprtc.util.LooperExecutor;
+import org.webrtc.AudioTrack;
import org.webrtc.CameraEnumerationAndroid;
import org.webrtc.DataChannel;
import org.webrtc.EglBase;
@@ -124,6 +125,9 @@ public class PeerConnectionClient {
private boolean renderVideo;
private VideoTrack localVideoTrack;
private VideoTrack remoteVideoTrack;
+ // enableAudio is set to true if audio should be sent.
+ private boolean enableAudio;
+ private AudioTrack localAudioTrack;
/**
* Peer connection parameters.
@@ -252,6 +256,8 @@ public class PeerConnectionClient {
renderVideo = true;
localVideoTrack = null;
remoteVideoTrack = null;
+ enableAudio = true;
+ localAudioTrack = null;
statsTimer = new Timer();
executor.execute(new Runnable() {
@@ -492,9 +498,7 @@ public class PeerConnectionClient {
mediaStream.addTrack(createVideoTrack(videoCapturer));
}
- mediaStream.addTrack(factory.createAudioTrack(
- AUDIO_TRACK_ID,
- factory.createAudioSource(audioConstraints)));
+ mediaStream.addTrack(createAudioTrack());
peerConnection.addStream(mediaStream);
if (peerConnectionParameters.aecDump) {
@@ -605,6 +609,18 @@ public class PeerConnectionClient {
}
}
+ public void setAudioEnabled(final boolean enable) {
+ executor.execute(new Runnable() {
+ @Override
+ public void run() {
+ enableAudio = enable;
+ if (localAudioTrack != null) {
+ localAudioTrack.setEnabled(enableAudio);
+ }
+ }
+ });
+ }
+
public void setVideoEnabled(final boolean enable) {
executor.execute(new Runnable() {
@Override
@@ -749,6 +765,14 @@ public class PeerConnectionClient {
});
}
+ private AudioTrack createAudioTrack() {
+ localAudioTrack = factory.createAudioTrack(
+ AUDIO_TRACK_ID,
+ factory.createAudioSource(audioConstraints));
+ localAudioTrack.setEnabled(enableAudio);
+ return localAudioTrack;
+ }
+
private VideoTrack createVideoTrack(VideoCapturerAndroid capturer) {
videoSource = factory.createVideoSource(capturer, videoConstraints);