Skip to content

Voice Broadcast - Fix playback stuck in buffering #7646

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 4 commits into from
Nov 29, 2022

Conversation

Florian14
Copy link
Contributor

Type of change

  • Feature
  • Bugfix
  • Technical
  • Other :

Content

Improvement related to the voice broadcast playback, fix issues with buffering state
Also fixed an issue when the live broadcast is ended, the playback was not automatically reset after listening to the last chunk.

Motivation and context

Sometimes, the (live) playback was stuck in a buffering state after a pause/resume from the recorder or when receiving new chunks after reaching the current duration

Screenshots / GIFs

Tests

Verify that the playback is not stuck in buffering when starting listening to a live voice broadcast (from the beggining & after reaching the end)
The playback should be automatically reset when the listening is over and the live VB has ended.

Tested devices

  • Physical
  • Emulator
  • OS version(s):

Checklist

@Florian14 Florian14 requested review from a team and onurays and removed request for a team November 25, 2022 14:58
@Florian14 Florian14 force-pushed the bugfix/fre/fix_playback_stuck_in_buffering branch from c302938 to 5330d9c Compare November 25, 2022 15:01
@@ -73,7 +72,7 @@ class VoiceBroadcastPlayerImpl @Inject constructor(
@MainThread
set(value) {
if (field != value) {
Timber.w("isLiveListening: $field -> $value")
Timber.w("## Voice Broadcast | isLiveListening: $field -> $value")
Copy link
Contributor

Choose a reason for hiding this comment

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

This will produce many logs, right? Can we avoid if not necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not so many, it will only log if the user is listening to a voice broadcast.
Then, if the VB is ended, it will log once (or not if the default value does not change). If the VB is live, it will log if the user scrolls in the playback or if the recorder pause/resume the recording, but in a quite acceptable frequency.
Btw, it doesn't need to warn, I changed it to debug

Same for the log about playingState, It can be a little more frequent but also only when listening to a VB. The frequency is still acceptable imo, and the log is useful for debugging.
Also changed to debug level

@@ -373,6 +376,19 @@ class VoiceBroadcastPlayerImpl @Inject constructor(
// Notify live mode change to all the listeners attached to the current voice broadcast id
listeners[voiceBroadcastId]?.forEach { listener -> listener.onLiveModeChanged(isLiveListening) }
}

// Live has ended and last chunk has been reached, we can stop the playback
if (!isLiveListening && playingState == State.BUFFERING && playlist.currentSequence == mostRecentVoiceBroadcastEvent?.content?.lastChunkSequence) {
Copy link
Contributor

Choose a reason for hiding this comment

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

To avoid possible bugs, we should encapsulate these logic in state data classes and create use case classes with unit test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree with you but I am not sure to follow exactly what you have in mind about the use cases. There are a lot of combinations with several parameters to take into account, For the moment, I don't know how many combinations there are and if I would be able to enumerate all of them.

I already refactored this class but I confirm it is still not perfect, it will require new refactoring and unit tests to prevent regression as every change can be dangerous. I created an issue to track the missing tests on this part. I'll try to improve this mechanism by introducing a state machine at this moment.

Copy link
Contributor

@onurays onurays left a comment

Choose a reason for hiding this comment

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

These changes are LGTM but this class has heavy logics. We need to separate them into use case class and add some unit tests.

@Florian14 Florian14 force-pushed the feature/fre/voice_broadcast_handle_event_deletion branch 2 times, most recently from f85f4cf to 620bebc Compare November 28, 2022 15:08
@Florian14 Florian14 force-pushed the bugfix/fre/fix_playback_stuck_in_buffering branch from ca00a46 to fe0bca7 Compare November 29, 2022 00:11
@sonarqubecloud
Copy link

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

Base automatically changed from feature/fre/voice_broadcast_handle_event_deletion to develop November 29, 2022 08:51
@Florian14 Florian14 merged commit 559af32 into develop Nov 29, 2022
@Florian14 Florian14 deleted the bugfix/fre/fix_playback_stuck_in_buffering branch November 29, 2022 08:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants