Skip to content

Commit

Permalink
chore: updated comment
Browse files Browse the repository at this point in the history
  • Loading branch information
deltork committed Mar 18, 2024
1 parent 861d7e6 commit de7f855
Showing 1 changed file with 21 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ export class ReadAlongComponent {
this.isScrolling = false;
}, 125);
}
isAutoPaused: boolean = false;
endOfPageTags: { [key: string]: number } = {};
autoPauseTimer: any;
endOfPageTags: Alignment = {};
finalTaggedWord: string;
/************
* LISTENERS *
Expand Down Expand Up @@ -891,7 +891,10 @@ export class ReadAlongComponent {
const sentence =
paragraphs[paragraphs.length - 1].querySelector("s:last-of-type");
const word = sentence.querySelector("w:last-of-type");
this.endOfPageTags[word.id] = parseFloat(word.getAttribute("dur"));
this.endOfPageTags[word.id] = [
parseFloat(word.getAttribute("time")),
parseFloat(word.getAttribute("dur")) * 1000,
];
this.finalTaggedWord = word.id;
} catch (err) {}
}
Expand Down Expand Up @@ -954,6 +957,7 @@ export class ReadAlongComponent {
this.reading$ = this.audio_howl_sprites._reading$
.pipe(distinctUntilChanged())
.subscribe((el_tag) => {
//console.log("reading",el_tag)
// Only highlight when playing
if (this.playing) {
//if auto pause is active and not on last word of the read along pause the audio
Expand All @@ -962,13 +966,22 @@ export class ReadAlongComponent {
el_tag in this.endOfPageTags &&
this.finalTaggedWord !== el_tag
) {
//wait for the audio of the last word
if (!this.isAutoPaused)
setTimeout(
//console.log(this.audio_howl_sprites.sound.seek() ,el_tag, this.endOfPageTags[el_tag], this.play_id);
//this is a work around to ignore id's not close to current sound time
//
const timeDiff = Math.round(
this.audio_howl_sprites.sound.seek() -
this.endOfPageTags[el_tag][0]
);
if (timeDiff == 0) {
if (this.autoPauseTimer)
window.clearTimeout(this.autoPauseTimer);

this.autoPauseTimer = window.setTimeout(
() => this.pause(),
this.endOfPageTags[el_tag] * 1000 - 150
this.endOfPageTags[el_tag][1] - 50
);
this.isAutoPaused = !this.isAutoPaused;
}
}
// Turn tag to query
let query = this.tagToQuery(el_tag);
Expand Down

0 comments on commit de7f855

Please sign in to comment.