Add Mic Toggle button to AppRTCDemo (Android).
BUG=webrtc:5671 Review URL: https://codereview.webrtc.org/1820113003 Cr-Commit-Position: refs/heads/master@{#12100}
This commit is contained in:
parent
8f59762897
commit
de3185521b
@ -47,6 +47,14 @@
|
||||
android:contentDescription="@string/disconnect_call"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"/>
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/button_call_toggle_mic"
|
||||
android:background="@android:drawable/ic_btn_speak_now"
|
||||
android:contentDescription="@string/toggle_mic"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"/>
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
|
||||
@ -18,6 +18,7 @@
|
||||
<string name="ok">OK</string>
|
||||
<string name="switch_camera">Switch front/back camera</string>
|
||||
<string name="toggle_debug">Toggle debug view</string>
|
||||
<string name="toggle_mic">Toggle microphone on/off</string>
|
||||
<string name="action_settings">Settings</string>
|
||||
<string name="add_room_description">Add new room to the list</string>
|
||||
<string name="remove_room_description">Remove room from the list</string>
|
||||
|
||||
@ -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()) {
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
||||
@ -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);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user