Skip to content
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

fix: Listen few audios at the same time [WPB-11180] #3639

Merged
merged 9 commits into from
Nov 26, 2024

Conversation

borichellow
Copy link
Contributor

@borichellow borichellow commented Nov 15, 2024

BugWPB-11180 [Android] I can listen to the same audio message at the same time

What's new in this PR?

Issues

STR:

  • have any group conversation open
  • receive an audio message
  • play it
  • while it’s playing, go to group details > media > files
  • on the received audio message, press play

Result:
Both audio messages play at the same time. The first one continues uninterrupted and the second message starts from the beginning

Causes (Optional)

Both Conversation and ConversationsMedia screens use ConversationMessagesViewModel which uses ConversationAudioMessagePlayer. As far as separate instance of ViewModel is created for each screen, separate player are used and each of it has no control over other.

Solutions

Added singleton ConversationAudioMessagePlayerProvider, which can provide player and counts usages of it.
So when new ViewModel needs player it will refer to the same instance of player and can pause previously played audio if needed. On the other hand: manager counts usages of player and when it's not needed anymore - remove it from memory.

@borichellow borichellow self-assigned this Nov 15, 2024
@echoes-hq echoes-hq bot added the echoes: unplanned Any work item that isn’t part of the product or technical roadmap. label Nov 15, 2024

@Singleton
Copy link
Member

Choose a reason for hiding this comment

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

making it a Singleton it not really the way to go since we do not want to keep it in memory forever maybe try @reusable instead ?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think there is potential for many resusable being used at the same time, when threads gets involved. Not sure if that matters in this case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

unfortunately @Reusable is useless here, as it doesn't guaranty "not re-creating" a new instance of Player. So i added a Singleton Provider, which will provide a player instance (create it if needed) and free space, when player is not used anymore

@codecov-commenter
Copy link

codecov-commenter commented Nov 15, 2024

Codecov Report

Attention: Patch coverage is 58.62069% with 12 lines in your changes missing coverage. Please review.

Project coverage is 46.03%. Comparing base (c911271) to head (057be71).

Files with missing lines Patch % Lines
...dia/audiomessage/ConversationAudioMessagePlayer.kt 57.69% 10 Missing and 1 partial ⚠️
...rsations/messages/ConversationMessagesViewModel.kt 66.66% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #3639      +/-   ##
===========================================
- Coverage    46.04%   46.03%   -0.02%     
===========================================
  Files          472      472              
  Lines        16108    16127      +19     
  Branches      2666     2670       +4     
===========================================
+ Hits          7417     7424       +7     
- Misses        7917     7928      +11     
- Partials       774      775       +1     
Files with missing lines Coverage Δ
...rsations/messages/ConversationMessagesViewModel.kt 65.98% <66.66%> (+0.17%) ⬆️
...dia/audiomessage/ConversationAudioMessagePlayer.kt 66.89% <57.69%> (-4.65%) ⬇️

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c911271...057be71. Read the comment docs.

---- 🚨 Try these New Features:

Copy link
Contributor

@damian-kaczmarek damian-kaczmarek left a comment

Choose a reason for hiding this comment

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

Rest of the code looks good

Copy link
Contributor

Built wire-android-staging-compat-pr-3639.apk is available for download

Copy link
Contributor

Built wire-android-dev-debug-pr-3639.apk is available for download

Copy link
Contributor

Built wire-android-staging-compat-pr-3639.apk is available for download

Copy link
Contributor

Built wire-android-dev-debug-pr-3639.apk is available for download

}
usageCount++

return player!!
Copy link
Contributor

Choose a reason for hiding this comment

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

[Just a thought] Im not a big fan of the !! operator. so maybe something like:

val player = player ?: ConversationAudioMessagePlayer(context, audioMediaPlayer, coreLogic).also { player = it }
usageCount++

return player

Copy link

sonarcloud bot commented Nov 25, 2024

Copy link
Contributor

Built wire-android-staging-compat-pr-3639.apk is available for download

Copy link
Contributor

Built wire-android-dev-debug-pr-3639.apk is available for download

@MohamadJaara MohamadJaara added this pull request to the merge queue Nov 26, 2024
Merged via the queue into develop with commit 286ad3f Nov 26, 2024
11 of 12 checks passed
@MohamadJaara MohamadJaara deleted the fix/listen_few_audios_at_the_same_time branch November 26, 2024 11:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
echoes: unplanned Any work item that isn’t part of the product or technical roadmap. size/S
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants