Skip to content

Use in-call volume and mode for EC #4481

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 11, 2025

Conversation

jmartinesp
Copy link
Member

@jmartinesp jmartinesp commented Mar 26, 2025

Content

When the call starts, get the list of audio devices and try to set the 'most likely to be used' device as audio input + output. This also changes the audio mode to 'in communication', making the volume rocker change the 'in-call' audio stream.

This works as a workaround for not being able to pick the audio output in the EC settings, since this is not supported by the Android WebView (and it doesn't seem like it'll be supported any time soon).

Note that adding a new audio device while in-call won't work, the workaround can't make that work too, sadly. We'll see if we can do something in the future.

Motivation and context

Should fix #4480.

Tests

  • Before starting a call, connect either some wired or wireless headphones, with microphone, if possible.
  • Start/join the call, check the audio input and output of the device is used.

Tested devices

  • Physical
  • Emulator
  • OS version(s): 14

Checklist

  • Changes have been tested on an Android device or Android emulator with API 24
  • UI change has been tested on both light and dark themes
  • Accessibility has been taken into account. See https://github.com/element-hq/element-x-android/blob/develop/CONTRIBUTING.md#accessibility
  • Pull request is based on the develop branch
  • Pull request title will be used in the release note, it clearly define what will change for the user
  • Pull request includes screenshots or videos if containing UI changes
  • You've made a self review of your PR

Copy link
Contributor

github-actions bot commented Mar 26, 2025

📱 Scan the QR code below to install the build (arm64 only) for this PR.
QR code
If you can't scan the QR code you can install the build via this link: https://i.diawi.com/e7EJMC

@@ -161,6 +167,10 @@ private fun CallWebView(
}
},
onRelease = { webView ->
// Reset audio mode
val audioManager = webView.context.getSystemService<AudioManager>()
audioManager?.mode = AudioManager.MODE_NORMAL
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe store the previous mode and restore it here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I saw in some issues (this is poorly documented, AFAICT) the app can be 'blacklisted' if it doesn't play any audio in the 6s after enabling this mode or doesn't return to the MODE_NORMAL when it's done playing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, thanks.

@jmartinesp jmartinesp force-pushed the fix/use-in-call-volume-for-element-call-audio branch from acdf636 to e5ec2c4 Compare March 27, 2025 08:23
Copy link

codecov bot commented Mar 27, 2025

Codecov Report

Attention: Patch coverage is 16.66667% with 20 lines in your changes missing coverage. Please review.

Project coverage is 80.05%. Comparing base (bec9239) to head (c19acb7).
Report is 22 commits behind head on develop.

Files with missing lines Patch % Lines
...roid/libraries/androidutils/compat/AudioManager.kt 11.11% 14 Missing and 2 partials ⚠️
...nt/android/features/call/impl/ui/CallScreenView.kt 33.33% 0 Missing and 4 partials ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #4481      +/-   ##
===========================================
- Coverage    80.08%   80.05%   -0.03%     
===========================================
  Files         2087     2088       +1     
  Lines        55121    55145      +24     
  Branches      6876     6884       +8     
===========================================
+ Hits         44143    44148       +5     
- Misses        8617     8631      +14     
- Partials      2361     2366       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@toger5
Copy link

toger5 commented Mar 27, 2025

I tested it and it works. I can change the output volume while in a call with the hardware buttons (without using androids per sink volume control ui)
The output device selection in EC does not work however. It will always defaults to the loudspeaker.

I think this makes sense to become its own issue?
It will need more work on the product to design how we want to control the output devices in EC.

It will would be interesting to have an experiment if it event works?
Since we send widget actions on mute/unmute i am wondering if we can throw together a short experiment with this pr:

  • muting the camera switches the android media device to the head piece
  • unmuting the camera switches to the loudspeaker
    ?

@toger5
Copy link

toger5 commented Mar 27, 2025

Another issue I observed with this is, that the min volume is still very audible (there is no 0 volume option for in call audio)

Which is very nice for the user so they will never be stuck with no sound and also what a normal call does.

It is still sth we need to be aware of, since we might want to be able to silence the phone if in a conference when someone else comes by in the real world.

I think this is sth we would like to solve in EC where we provide a mute output button or similar.

@toger5
Copy link

toger5 commented Apr 2, 2025

@jmartinesp
It is okay to never be able to mute the call: element-hq/element-call#3137
So using the in-call output is the way to go.

@jmartinesp jmartinesp added the PR-Bugfix For bug fix label Apr 9, 2025
@jmartinesp jmartinesp marked this pull request as ready for review April 9, 2025 13:58
@jmartinesp jmartinesp requested a review from a team as a code owner April 9, 2025 13:58
@jmartinesp jmartinesp requested review from ganfra and removed request for a team April 9, 2025 13:58
@jmartinesp
Copy link
Member Author

@toger5 I think you already did, but can you confirm that even though the changes don't fix all the issues, we can merge this as is and iterate later if needed? Thanks!

@toger5
Copy link

toger5 commented Apr 9, 2025

@toger5 I think you already did, but can you confirm that even though the changes don't fix all the issues, we can merge this as is and iterate later if needed? Thanks!

Yes when i tested it this was already an imporvement and worked as expected (volume rocker changed call sound)

// The built-in earpiece of the device
AudioDeviceInfo.TYPE_BUILTIN_EARPIECE,
// The built-in speaker of the device
AudioDeviceInfo.TYPE_BUILTIN_SPEAKER,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For Video Call, I guess TYPE_BUILTIN_SPEAKER should have a higher priority than TYPE_BUILTIN_EARPIECE, no?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, nice catch.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once we have the "EC stop audio output"/"EC start/continue audio output" widget actions it should be easy to switch from TYPE_BUILTIN_SPEAKER to TYPE_BUILTIN_EARPIECE when the phone is put in standby right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't say without having tested it first. In theory it should be.

Copy link
Member

@bmarty bmarty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update!

@jmartinesp jmartinesp merged commit a6d7741 into develop Apr 11, 2025
29 of 31 checks passed
@jmartinesp jmartinesp deleted the fix/use-in-call-volume-for-element-call-audio branch April 11, 2025 14:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR-Bugfix For bug fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Using the volume rocker during calls is not affecting the call audio volume.
3 participants