Skip to content

Commit

Permalink
Merge pull request #1 from chrisvire/play-mode-button-audio
Browse files Browse the repository at this point in the history
Fix issues with Repeat Selection
  • Loading branch information
ChristopherRankin authored Oct 8, 2023
2 parents cbde57e + 7d358a0 commit bb1a58a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
12 changes: 11 additions & 1 deletion src/lib/data/audio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
Expand Down Expand Up @@ -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();
Expand Down
21 changes: 14 additions & 7 deletions src/lib/data/stores/audio.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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);
Expand Down

0 comments on commit bb1a58a

Please sign in to comment.