show enable/disable video in video calls

This commit is contained in:
Daniel Gultsch 2020-04-15 19:16:47 +02:00
parent 445009c558
commit 01a9a52990
8 changed files with 89 additions and 35 deletions

View File

@ -410,12 +410,16 @@ public class RtpSessionActivity extends XmppActivity implements XmppConnectionSe
@SuppressLint("RestrictedApi") @SuppressLint("RestrictedApi")
private void updateInCallButtonConfiguration(final RtpEndUserState state) { private void updateInCallButtonConfiguration(final RtpEndUserState state) {
if (state == RtpEndUserState.CONNECTED) { if (state == RtpEndUserState.CONNECTED) {
final AppRTCAudioManager audioManager = requireRtpConnection().getAudioManager(); if (getMedia().contains(Media.VIDEO)) {
updateInCallButtonConfiguration( updateInCallButtonConfigurationVideo(requireRtpConnection().isVideoEnabled());
audioManager.getSelectedAudioDevice(), } else {
audioManager.getAudioDevices().size(), final AppRTCAudioManager audioManager = requireRtpConnection().getAudioManager();
requireRtpConnection().isMicrophoneEnabled() updateInCallButtonConfigurationSpeaker(
); audioManager.getSelectedAudioDevice(),
audioManager.getAudioDevices().size()
);
}
updateInCallButtonConfigurationMicrophone(requireRtpConnection().isMicrophoneEnabled());
} else { } else {
this.binding.inCallActionLeft.setVisibility(View.GONE); this.binding.inCallActionLeft.setVisibility(View.GONE);
this.binding.inCallActionRight.setVisibility(View.GONE); this.binding.inCallActionRight.setVisibility(View.GONE);
@ -423,48 +427,75 @@ public class RtpSessionActivity extends XmppActivity implements XmppConnectionSe
} }
@SuppressLint("RestrictedApi") @SuppressLint("RestrictedApi")
private void updateInCallButtonConfiguration(final AppRTCAudioManager.AudioDevice selectedAudioDevice, final int numberOfChoices, final boolean microphoneEnabled) { private void updateInCallButtonConfigurationSpeaker(final AppRTCAudioManager.AudioDevice selectedAudioDevice, final int numberOfChoices) {
switch (selectedAudioDevice) { switch (selectedAudioDevice) {
case EARPIECE: case EARPIECE:
this.binding.inCallActionLeft.setImageResource(R.drawable.ic_volume_off_black_24dp); this.binding.inCallActionRight.setImageResource(R.drawable.ic_volume_off_black_24dp);
if (numberOfChoices >= 2) { if (numberOfChoices >= 2) {
this.binding.inCallActionLeft.setOnClickListener(this::switchToSpeaker); this.binding.inCallActionRight.setOnClickListener(this::switchToSpeaker);
} else { } else {
this.binding.inCallActionLeft.setOnClickListener(null); this.binding.inCallActionRight.setOnClickListener(null);
this.binding.inCallActionLeft.setClickable(false); this.binding.inCallActionRight.setClickable(false);
} }
break; break;
case WIRED_HEADSET: case WIRED_HEADSET:
this.binding.inCallActionLeft.setImageResource(R.drawable.ic_headset_black_24dp); this.binding.inCallActionRight.setImageResource(R.drawable.ic_headset_black_24dp);
this.binding.inCallActionLeft.setOnClickListener(null); this.binding.inCallActionRight.setOnClickListener(null);
this.binding.inCallActionLeft.setClickable(false); this.binding.inCallActionRight.setClickable(false);
break; break;
case SPEAKER_PHONE: case SPEAKER_PHONE:
this.binding.inCallActionLeft.setImageResource(R.drawable.ic_volume_up_black_24dp); this.binding.inCallActionRight.setImageResource(R.drawable.ic_volume_up_black_24dp);
if (numberOfChoices >= 2) { if (numberOfChoices >= 2) {
this.binding.inCallActionLeft.setOnClickListener(this::switchToEarpiece); this.binding.inCallActionRight.setOnClickListener(this::switchToEarpiece);
} else { } else {
this.binding.inCallActionLeft.setOnClickListener(null); this.binding.inCallActionRight.setOnClickListener(null);
this.binding.inCallActionLeft.setClickable(false); this.binding.inCallActionRight.setClickable(false);
} }
break; break;
case BLUETOOTH: case BLUETOOTH:
this.binding.inCallActionLeft.setImageResource(R.drawable.ic_bluetooth_audio_black_24dp); this.binding.inCallActionRight.setImageResource(R.drawable.ic_bluetooth_audio_black_24dp);
this.binding.inCallActionLeft.setOnClickListener(null); this.binding.inCallActionRight.setOnClickListener(null);
this.binding.inCallActionLeft.setClickable(false); this.binding.inCallActionRight.setClickable(false);
break; break;
} }
this.binding.inCallActionLeft.setVisibility(View.VISIBLE);
if (microphoneEnabled) {
this.binding.inCallActionRight.setImageResource(R.drawable.ic_mic_black_24dp);
this.binding.inCallActionRight.setOnClickListener(this::disableMicrophone);
} else {
this.binding.inCallActionRight.setImageResource(R.drawable.ic_mic_off_black_24dp);
this.binding.inCallActionRight.setOnClickListener(this::enableMicrophone);
}
this.binding.inCallActionRight.setVisibility(View.VISIBLE); this.binding.inCallActionRight.setVisibility(View.VISIBLE);
} }
@SuppressLint("RestrictedApi")
private void updateInCallButtonConfigurationVideo(final boolean videoEnabled) {
this.binding.inCallActionRight.setVisibility(View.VISIBLE);
if (videoEnabled) {
this.binding.inCallActionRight.setImageResource(R.drawable.ic_videocam_black_24dp);
this.binding.inCallActionRight.setOnClickListener(this::disableVideo);
} else {
this.binding.inCallActionRight.setImageResource(R.drawable.ic_videocam_off_black_24dp);
this.binding.inCallActionRight.setOnClickListener(this::enableVideo);
}
}
private void enableVideo(View view) {
requireRtpConnection().setVideoEnabled(true);
updateInCallButtonConfigurationVideo(true);
}
private void disableVideo(View view) {
requireRtpConnection().setVideoEnabled(false);
updateInCallButtonConfigurationVideo(false);
}
@SuppressLint("RestrictedApi")
private void updateInCallButtonConfigurationMicrophone(final boolean microphoneEnabled) {
if (microphoneEnabled) {
this.binding.inCallActionLeft.setImageResource(R.drawable.ic_mic_black_24dp);
this.binding.inCallActionLeft.setOnClickListener(this::disableMicrophone);
} else {
this.binding.inCallActionLeft.setImageResource(R.drawable.ic_mic_off_black_24dp);
this.binding.inCallActionLeft.setOnClickListener(this::enableMicrophone);
}
this.binding.inCallActionLeft.setVisibility(View.VISIBLE);
}
private void updateVideoViews() { private void updateVideoViews() {
final Optional<VideoTrack> localVideoTrack = requireRtpConnection().geLocalVideoTrack(); final Optional<VideoTrack> localVideoTrack = requireRtpConnection().geLocalVideoTrack();
if (localVideoTrack.isPresent()) { if (localVideoTrack.isPresent()) {
@ -572,12 +603,11 @@ public class RtpSessionActivity extends XmppActivity implements XmppConnectionSe
public void onAudioDeviceChanged(AppRTCAudioManager.AudioDevice selectedAudioDevice, Set<AppRTCAudioManager.AudioDevice> availableAudioDevices) { public void onAudioDeviceChanged(AppRTCAudioManager.AudioDevice selectedAudioDevice, Set<AppRTCAudioManager.AudioDevice> availableAudioDevices) {
Log.d(Config.LOGTAG, "onAudioDeviceChanged in activity: selected:" + selectedAudioDevice + ", available:" + availableAudioDevices); Log.d(Config.LOGTAG, "onAudioDeviceChanged in activity: selected:" + selectedAudioDevice + ", available:" + availableAudioDevices);
try { try {
if (requireRtpConnection().getEndUserState() == RtpEndUserState.CONNECTED) { if (requireRtpConnection().getEndUserState() == RtpEndUserState.CONNECTED && !getMedia().contains(Media.VIDEO)) {
final AppRTCAudioManager audioManager = requireRtpConnection().getAudioManager(); final AppRTCAudioManager audioManager = requireRtpConnection().getAudioManager();
updateInCallButtonConfiguration( updateInCallButtonConfigurationSpeaker(
audioManager.getSelectedAudioDevice(), audioManager.getSelectedAudioDevice(),
audioManager.getAudioDevices().size(), audioManager.getAudioDevices().size()
requireRtpConnection().isMicrophoneEnabled()
); );
} }
putProximityWakeLockInProperState(); putProximityWakeLockInProperState();

View File

@ -930,6 +930,14 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web
webRTCWrapper.setMicrophoneEnabled(enabled); webRTCWrapper.setMicrophoneEnabled(enabled);
} }
public boolean isVideoEnabled() {
return webRTCWrapper.isVideoEnabled();
}
public void setVideoEnabled(final boolean enabled) {
webRTCWrapper.setVideoEnabled(enabled);
}
@Override @Override
public void onAudioDeviceChanged(AppRTCAudioManager.AudioDevice selectedAudioDevice, Set<AppRTCAudioManager.AudioDevice> availableAudioDevices) { public void onAudioDeviceChanged(AppRTCAudioManager.AudioDevice selectedAudioDevice, Set<AppRTCAudioManager.AudioDevice> availableAudioDevices) {
xmppConnectionService.notifyJingleRtpConnectionUpdate(selectedAudioDevice, availableAudioDevices); xmppConnectionService.notifyJingleRtpConnectionUpdate(selectedAudioDevice, availableAudioDevices);

View File

@ -228,7 +228,7 @@ public class WebRTCWrapper {
} }
} }
public boolean isMicrophoneEnabled() { boolean isMicrophoneEnabled() {
final AudioTrack audioTrack = this.localAudioTrack; final AudioTrack audioTrack = this.localAudioTrack;
if (audioTrack == null) { if (audioTrack == null) {
throw new IllegalStateException("Local audio track does not exist (yet)"); throw new IllegalStateException("Local audio track does not exist (yet)");
@ -236,7 +236,7 @@ public class WebRTCWrapper {
return audioTrack.enabled(); return audioTrack.enabled();
} }
public void setMicrophoneEnabled(final boolean enabled) { void setMicrophoneEnabled(final boolean enabled) {
final AudioTrack audioTrack = this.localAudioTrack; final AudioTrack audioTrack = this.localAudioTrack;
if (audioTrack == null) { if (audioTrack == null) {
throw new IllegalStateException("Local audio track does not exist (yet)"); throw new IllegalStateException("Local audio track does not exist (yet)");
@ -244,6 +244,22 @@ public class WebRTCWrapper {
audioTrack.setEnabled(enabled); audioTrack.setEnabled(enabled);
} }
public boolean isVideoEnabled() {
final VideoTrack videoTrack = this.localVideoTrack;
if (videoTrack == null) {
throw new IllegalStateException("Local video track does not exist");
}
return videoTrack.enabled();
}
public void setVideoEnabled(final boolean enabled) {
final VideoTrack videoTrack = this.localVideoTrack;
if (videoTrack == null) {
throw new IllegalStateException("Local video track does not exist");
}
videoTrack.setEnabled(enabled);
}
public ListenableFuture<SessionDescription> createOffer() { public ListenableFuture<SessionDescription> createOffer() {
return Futures.transformAsync(getPeerConnectionFuture(), peerConnection -> { return Futures.transformAsync(getPeerConnectionFuture(), peerConnection -> {
final SettableFuture<SessionDescription> future = SettableFuture.create(); final SettableFuture<SessionDescription> future = SettableFuture.create();

Binary file not shown.

After

Width:  |  Height:  |  Size: 260 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 193 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 274 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 375 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 447 B