Skip to content

android: cancel stale smooth-volume loop in MediaController - #933

Open
cemaliplt wants to merge 1 commit into
librepods-org:mainfrom
cemaliplt:cem/android-fix6
Open

cemaliplt wants to merge 1 commit into
librepods-org:mainfrom
cemaliplt:cem/android-fix6

Conversation

@cemaliplt

Copy link
Copy Markdown

What was wrong

MediaController.kt:347-362: smoothVolumeTransition posts its Runnable anonymously and never stores it. When startSpeaking and stopSpeaking overlap, two loops keep calling setStreamVolume with different targets, so the final volume depends on which write lands last.

Fix

Keep the Runnable in a private volumeRunnable; remove the previous callback before posting a new transition.

Verified

./gradlew :app:compileFossDebugKotlin and :app:compilePlayDebugKotlin both pass on this branch (BUILD SUCCESSFUL, no new warnings). The change was also checked by reading the code.

Not verified

Not run on a device or with AirPods; no unit test (the project has no Android test setup for this class).

🤖 Generated with Claude Code

What was wrong: MediaController.kt:347-362 posts the smoothVolumeTransition Runnable anonymously and never stores it. When startSpeaking (line 327) and stopSpeaking (line 339) overlap, two loops keep calling setStreamVolume with different targets, so the final volume depends on which write lands last.

Fix: keep the posted Runnable in a new private var volumeRunnable; before posting a new transition, handler.removeCallbacks on the previous one, then store and post the new one.

How checked: code reading only, not built (no Android SDK here). Re-read the diff: handler is Handler(Looper.getMainLooper()) so removeCallbacks uses the same object reference; 'this' inside postDelayed still refers to the anonymous Runnable; the new field is declared inside the object.
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.

1 participant