Skip to content

Fix voice message not resuming after playing voice recording in composer#6317

Open
gpunto wants to merge 2 commits intov7from
fix-message-vs-composer-audioplayer-conflict
Open

Fix voice message not resuming after playing voice recording in composer#6317
gpunto wants to merge 2 commits intov7from
fix-message-vs-composer-audioplayer-conflict

Conversation

@gpunto
Copy link
Copy Markdown
Contributor

@gpunto gpunto commented Mar 31, 2026

Goal

Fix voice message playback in the message list getting stuck after playing a voice recording in the composer.

Repro: play a voice message in the message list → while playing, play the voice recording in the composer → try to resume the message list one → it doesn't play. Playing a different message list track first unblocks the original one.

Implementation

The root cause is that AudioRecordingController (composer recording preview) and AudioPlayerController (message list) both use the shared AudioPlayer singleton independently. When the recording controller plays audio, it changes AudioPlayer.currentPlayingId without the message list controller knowing. The message list controller's state still considers the interrupted track as "current and partially played", so togglePlayback takes the resume() path — but AudioPlayer.resume() silently fails because currentAudioHash no longer matches.

  • Check audioPlayer.currentPlayingId in togglePlayback to detect when the underlying player has been taken over by another consumer
  • When the track has partial progress but is no longer loaded in the player, save the playback progress and call play() (full reload with seek) instead of resume()

Testing

  1. Open a channel with voice messages in the list
  2. Record a voice message without sending it (to do so, lock the recording button and then press stop)
  3. Play a voice message in the message list
  4. While it's playing, play the recording preview in the composer
  5. Tap the message list voice message again → verify it resumes from where it left off
  6. Verify normal message list playback (switching between tracks) still works

Summary by CodeRabbit

  • Bug Fixes
    • Improved audio player pause/resume state handling for more accurate playback control
    • Fixed audio progress persistence when switching between different audio files

@gpunto gpunto added the pr:bug Bug fix label Mar 31, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 31, 2026

PR checklist ✅

All required conditions are satisfied:

  • Title length is OK (or ignored by label).
  • At least one pr: label exists.
  • Sections ### Goal, ### Implementation, and ### Testing are filled.

🎉 Great job! This PR is ready for review.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 31, 2026

SDK Size Comparison 📏

SDK Before After Difference Status
stream-chat-android-client 5.25 MB 5.86 MB 0.61 MB 🔴
stream-chat-android-ui-components 10.60 MB 11.17 MB 0.57 MB 🔴
stream-chat-android-compose 12.81 MB 12.41 MB -0.41 MB 🚀

@gpunto gpunto marked this pull request as ready for review March 31, 2026 10:31
@gpunto gpunto requested a review from a team as a code owner March 31, 2026 10:31
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 31, 2026

Walkthrough

The togglePlayback method in AudioPlayerController was refactored to handle audio progress tracking more intelligently. A single conditional was split into three distinct cases based on whether partial progress exists and if the target audio is currently loaded, enabling refined pause/resume, progress persistence, or fresh playback logic.

Changes

Cohort / File(s) Summary
Audio Playback Logic Refinement
stream-chat-android-ui-common/src/main/kotlin/io/getstream/chat/android/ui/common/feature/messages/list/AudioPlayerController.kt
Refactored togglePlayback control flow to distinguish three cases: toggling pause/resume for already-loaded partially-progressed audio, persisting progress when switching to a different audio file, and starting from the beginning when no partial progress exists. Added minor whitespace adjustments to startSeek and seekTo branches.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A rabbit hops through audio streams,
Progress saved like carrots in dreams,
Pause, resume, or start anew—
The player knows what to do! 🎵

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main issue being fixed: voice message resumption after playing a composer recording.
Description check ✅ Passed The description provides Goal, Implementation, and Testing sections as required by the template, though UI Changes and Contributor Checklist sections are not completed.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-message-vs-composer-audioplayer-conflict

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
stream-chat-android-ui-common/src/main/kotlin/io/getstream/chat/android/ui/common/feature/messages/list/AudioPlayerController.kt (1)

81-84: Minor typo in log message.

The semicolon after currentPlayingId should likely be a colon for consistency with the other key-value pairs in this log statement.

📝 Suggested fix
         logger.d {
-            "[togglePlayback] audioHash: $audioHash, currentPlayingId; $currentPlayingId, " +
+            "[togglePlayback] audioHash: $audioHash, currentPlayingId: $currentPlayingId, " +
                 "isCurrentTrack: $isCurrentTrack, isProgressRunning: $isProgressRunning, state: ${curState.stringify()}"
         }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@stream-chat-android-ui-common/src/main/kotlin/io/getstream/chat/android/ui/common/feature/messages/list/AudioPlayerController.kt`
around lines 81 - 84, In AudioPlayerController's logging in the togglePlayback
flow (see the logger.d block in AudioPlayerController.kt), change the typo in
the log string so "currentPlayingId; $currentPlayingId" uses a colon instead of
a semicolon for consistent key-value formatting (i.e., "currentPlayingId:
$currentPlayingId"); no other behavior changes required.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In
`@stream-chat-android-ui-common/src/main/kotlin/io/getstream/chat/android/ui/common/feature/messages/list/AudioPlayerController.kt`:
- Around line 81-84: In AudioPlayerController's logging in the togglePlayback
flow (see the logger.d block in AudioPlayerController.kt), change the typo in
the log string so "currentPlayingId; $currentPlayingId" uses a colon instead of
a semicolon for consistent key-value formatting (i.e., "currentPlayingId:
$currentPlayingId"); no other behavior changes required.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 512ca0eb-22f7-4eb6-833a-573599011913

📥 Commits

Reviewing files that changed from the base of the PR and between 1230179 and 7598be9.

📒 Files selected for processing (1)
  • stream-chat-android-ui-common/src/main/kotlin/io/getstream/chat/android/ui/common/feature/messages/list/AudioPlayerController.kt

@sonarqubecloud
Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr:bug Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant