Repository navigation
Fix next sura starting at ayah 2 in gapless continuous playback - #4057
Open
m86hussein wants to merge 1 commit into
Open
m86hussein wants to merge 1 commit into
m86hussein wants to merge 1 commit into
Conversation
When gapless playback passes the end-of-sura marker, the queue moves to ayah 1 of the next sura and playAudio() loads that sura's timings asynchronously. The old file kept playing meanwhile; if it reached its end first, onPlayerCompleted advanced the queue again, so the next sura started from ayah 2. Stop the current player before the async load so no stale completion can advance the queue. Fixes quran#4055 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
With a gapless reciter and continuous playback, the next sura can start from ayah 2 instead of ayah 1 (#4055).
The bug
When
updateAudioPlayPositionpasses the end-of-sura marker (ayahTimings[999]), it moves the queue tosura + 1 : 1and callsplayAudio(true). For gapless recitersplayAudio()setsstate = Stoppedand then loads the next sura's timings in a coroutine (updateGaplessData→TimingRepository.timings, which suspends onDispatchers.IO). Only after that does it reset the player and start the new file.The old player was never stopped, so it kept playing the tail of the previous file during that load. The player is built on the service's handler thread, so its callbacks run on the same thread as the coroutine and can run while the coroutine is suspended. If the old file reaches its end first, which is likely for recordings that end right at the 999 marker (see 566fb5a), this happens:
STATE_ENDED→onPlayerCompleted()→audioQueue.playNextAyah(false)moves the queue fromN+1:1toN+1:2.getSeekPosition()returns-1becausegaplessSurais stillN, so nothing happens.N+1atayahTimings[2], skipping ayah 1.The fix
playAudio()now callsplayer?.stop()before the async timing load. A stopped player can't send a staleSTATE_ENDED, and ExoPlayer drops any pending state updates oncestop()is called. TheSTATE_IDLEcallback this triggers does nothing, becausestateis alreadyStopped.playAudio(flag, timings)already stops and resets the player before starting the new file, so this only moves the stop earlier.The change is a single line in
AudioService.playAudio().Testing
./gradlew :app:testMadaniDebugUnitTest --tests "*Audio*"passes (25 tests:AudioQueueTest,AudioPresenterTest,AudioUtilsTest,AudioRevisionSettingsTest).AudioServicehas no unit tests, and reproducing this would need a mocked ExoPlayer plus controlled coroutine timing. I can add one if you have a preferred approach.Fixes #4055
AI disclosure: this PR was drafted with GitHub Copilot and opened by @m86hussein, who is responsible for it.