diff --git a/src/lib/data/audio.ts b/src/lib/data/audio.ts index 7dd47cbbf..7b020e425 100644 --- a/src/lib/data/audio.ts +++ b/src/lib/data/audio.ts @@ -30,7 +30,16 @@ audioPlayerStore.subscribe(async (value) => { await getAudio(); }); export let currentPlayMode; -playMode.subscribe((value) => (currentPlayMode = value)); +playMode.subscribe((value) => { + if ( + currentPlayMode && + currentPlayMode.mode !== value.mode && + value.mode === PLAYMODE_REPEAT_SELECTION + ) { + value.range = getCurrentVerseTiming(); + } + currentPlayMode = value; +}); // produces the cache key for the mru audio cache function cacheKey(collection, book, chapter) { return `${collection}-${book}-${chapter}`; @@ -134,6 +143,7 @@ export function seek(position) { pause(); currentAudioPlayer.audio.currentTime = position; currentAudioPlayer.progress = position; + playMode.set({ ...currentPlayMode, range: getCurrentVerseTiming() }); audioPlayerStore.set(currentAudioPlayer); if (playing === true) { play(); diff --git a/src/lib/data/stores/audio.js b/src/lib/data/stores/audio.js index 4873cd633..d9b7fe4e1 100644 --- a/src/lib/data/stores/audio.js +++ b/src/lib/data/stores/audio.js @@ -35,9 +35,10 @@ export const PLAYMODE_STOP = 'stop'; export const PLAYMODE_REPEAT_PAGE = 'repeatPage'; export const PLAYMODE_REPEAT_SELECTION = 'repeatSelection'; +export const defaultPlayModeRange = { start: 0, end: 0 }; export const defaultPlayMode = { mode: config.mainFeatures['audio-goto-next-chapter'] ? PLAYMODE_CONTINUE : PLAYMODE_STOP, - range: { start: 0, end: 0 }, + range: defaultPlayModeRange, continue: false }; function createPlayMode() { @@ -47,22 +48,28 @@ function createPlayMode() { set: external.set, next: (hasTiming) => { const { mode, range } = get(external); - let next = mode; + let nextMode = mode; + let nextRange = range; switch (mode) { case PLAYMODE_CONTINUE: - next = PLAYMODE_STOP; + nextMode = PLAYMODE_STOP; break; case PLAYMODE_STOP: - next = PLAYMODE_REPEAT_PAGE; + nextMode = PLAYMODE_REPEAT_PAGE; break; case PLAYMODE_REPEAT_PAGE: - next = hasTiming ? PLAYMODE_REPEAT_SELECTION : PLAYMODE_CONTINUE; + if (hasTiming) { + nextMode = PLAYMODE_REPEAT_SELECTION; + nextRange = defaultPlayModeRange; + } else { + nextMode = PLAYMODE_CONTINUE; + } break; case PLAYMODE_REPEAT_SELECTION: - next = PLAYMODE_CONTINUE; + nextMode = PLAYMODE_CONTINUE; break; } - external.set({ mode: next, range }); + external.set({ mode: nextMode, range: nextRange }); }, reset: () => { external.set(defaultPlayMode);