From 8475a28dc5fb8696a0dc8ab84a8fbfeade8c6076 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Mon, 25 May 2020 10:43:56 +0200 Subject: [PATCH] control voice call volume when playing audio through earpiece. fixes #3705 --- .../eu/siacs/conversations/ui/adapter/MessageAdapter.java | 6 +++++- .../java/eu/siacs/conversations/ui/service/AudioPlayer.java | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java index 52fef833f..662f03c93 100644 --- a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java +++ b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java @@ -75,8 +75,8 @@ import eu.siacs.conversations.utils.MessageUtils; import eu.siacs.conversations.utils.StylingHelper; import eu.siacs.conversations.utils.TimeFrameUtils; import eu.siacs.conversations.utils.UIHelper; -import eu.siacs.conversations.xmpp.mam.MamReference; import eu.siacs.conversations.xmpp.Jid; +import eu.siacs.conversations.xmpp.mam.MamReference; public class MessageAdapter extends ArrayAdapter implements CopyTextView.CopyHandler { @@ -119,6 +119,10 @@ public class MessageAdapter extends ArrayAdapter implements CopyTextVie activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); } + public void setVolumeControl(final int stream) { + activity.setVolumeControlStream(stream); + } + public void setOnContactPictureClicked(OnContactPictureClicked listener) { this.mOnContactPictureClickedListener = listener; } diff --git a/src/main/java/eu/siacs/conversations/ui/service/AudioPlayer.java b/src/main/java/eu/siacs/conversations/ui/service/AudioPlayer.java index 67ee87da2..61f7b3e29 100644 --- a/src/main/java/eu/siacs/conversations/ui/service/AudioPlayer.java +++ b/src/main/java/eu/siacs/conversations/ui/service/AudioPlayer.java @@ -363,12 +363,13 @@ public class AudioPlayer implements View.OnClickListener, MediaPlayer.OnCompleti if (AudioPlayer.player == null || !AudioPlayer.player.isPlaying()) { return; } - int streamType; + final int streamType; if (event.values[0] < 5f && event.values[0] != proximitySensor.getMaximumRange()) { streamType = AudioManager.STREAM_VOICE_CALL; } else { streamType = AudioManager.STREAM_MUSIC; } + messageAdapter.setVolumeControl(streamType); double position = AudioPlayer.player.getCurrentPosition(); double duration = AudioPlayer.player.getDuration(); double progress = position / duration; @@ -407,6 +408,7 @@ public class AudioPlayer implements View.OnClickListener, MediaPlayer.OnCompleti wakeLock.release(); } } + messageAdapter.setVolumeControl(AudioManager.STREAM_MUSIC); } private ViewHolder getCurrentViewHolder() {