Skip to content

fix: remove audio pause during zero-delay verse transitions - #3318

Open
Mubashir78 wants to merge 1 commit into
quran:productionfrom
Mubashir78:fix/seamless-verse-transitions
Open

fix: remove audio pause during zero-delay verse transitions#3318
Mubashir78 wants to merge 1 commit into
quran:productionfrom
Mubashir78:fix/seamless-verse-transitions

Conversation

@Mubashir78

Copy link
Copy Markdown

Problem

During repeat mode playback, the audio player always pauses before seeking to the next verse, even when the delay between verses is set to zero. This creates an audible gap (voice cutoff) at verse boundaries.

The issue is in the REPEAT_AYAH action of the audio player state machine, which unconditionally calls pauseAudio before setAudioPlayerCurrentTime.

Root Cause

In audioPlayerMachine.ts, the REPEAT_AYAH transition in PLAYING.ACTIVE state always:

  1. Pauses the audio element (pauseAudio)
  2. Seeks to the next verse timestamp (setAudioPlayerCurrentTime)
  3. Transitions to DELAYING state

Even when verseDelay === 0 (no configured delay), the pause creates a brief silence between verses.

Fix

Split the REPEAT_AYAH transition into two guarded paths:

  • When verseDelay > 0: Preserves existing behavior (pause, seek, go to DELAYING state) for users who configured a delay between verses.
  • When verseDelay === 0: Skips the pause entirely and seeks directly to the next verse timestamp while audio keeps playing, going straight back to PLAYING.ACTIVE. This produces seamless transitions with no voice cutoff.

Changes

src/xstate/actors/audioPlayer/audioPlayerMachine.ts:

  • Split REPEAT_AYAH handler from a single transition into two guarded transitions
  • Added hasVerseDelay guard: (context, event) => event.verseDelay > 0
  • First transition (with guard): preserves pause + seek + DELAYING for delay > 0
  • Second transition (fallback): seek only, no pause, stays in PLAYING.ACTIVE

Testing

Standalone state machine tests verified all assertions pass:

  1. verseDelay > 0: machine pauses audio and enters DELAYING state
  2. verseDelay === 0: machine skips pause and stays in PLAYING.ACTIVE
  3. Multiple consecutive transitions with zero delay: no pauses, all seamless
  4. Ayah number and seek time correctly updated in all cases

The audio player always paused before seeking to the next verse during
repeat mode, even when the delay between verses was set to zero. This
created an audible gap (voice cutoff) at verse boundaries.

Split the REPEAT_AYAH transition into two guarded paths:
- When verseDelay > 0: preserve existing pause-then-seek behavior
  so users who configured a delay still hear the intended pause.
- When verseDelay === 0: skip the pause entirely and seek directly
  to the next verse timestamp while audio keeps playing, producing
  a seamless transition with no voice cutoff.

Added hasVerseDelay guard to the audio player state machine to
distinguish between the two cases.
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