Skip to content

Commit

Permalink
Merge pull request #387 from d-i-t-a/bugfix/media-overlay-loop-issue
Browse files Browse the repository at this point in the history
media overlay loop issue
  • Loading branch information
aferditamuriqi authored Sep 21, 2022
2 parents 9257391 + 200cbcf commit ec64e08
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 26 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@d-i-t-a/reader",
"version": "2.1.0-beta.11",
"version": "2.1.0-beta.12",
"description": "A viewer application for EPUB files.",
"repository": "https://github.com/d-i-t-a/R2D2BC",
"license": "Apache-2.0",
Expand Down
54 changes: 31 additions & 23 deletions src/modules/mediaoverlays/MediaOverlayModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,17 +185,19 @@ export class MediaOverlayModule implements ReaderModule {
);
} else {
if (this.audioElement) {
await this.audioElement?.pause();
await this.audioElement.pause();
}
if (this.currentLinks.length > 1 && this.currentLinkIndex === 0) {
this.currentLinkIndex++;
await this.playLink();
} else {
if (this.settings.autoTurn && this.settings.playing) {
this.audioElement?.pause();
if (this.audioElement) {
await this.audioElement.pause();
}
this.delegate.nextResource();
} else {
this.stopReadAloud();
await this.stopReadAloud();
}
}
}
Expand All @@ -204,7 +206,10 @@ export class MediaOverlayModule implements ReaderModule {
async startReadAloud() {
if (this.delegate.rights.enableMediaOverlays) {
this.settings.playing = true;
if (this.audioElement) {
if (
this.audioElement &&
this.currentLinks[this.currentLinkIndex]?.Properties.MediaOverlay
) {
const timeToSeekTo = this.currentAudioBegin
? this.currentAudioBegin
: 0;
Expand All @@ -231,17 +236,17 @@ export class MediaOverlayModule implements ReaderModule {
}
async stopReadAloud() {
if (this.delegate.rights.enableMediaOverlays) {
if (this.currentLinkIndex > 0) await this.playLink();
this.settings.playing = false;
this.audioElement?.pause();
this.audioElement.pause();

if (this.play) this.play.style.removeProperty("display");
if (this.pause) this.pause.style.display = "none";
}
}
pauseReadAloud() {
if (this.delegate.rights.enableMediaOverlays) {
this.settings.playing = false;
this.audioElement?.pause();
this.audioElement.pause();
if (this.play) this.play.style.removeProperty("display");
if (this.pause) this.pause.style.display = "none";
}
Expand Down Expand Up @@ -334,6 +339,7 @@ export class MediaOverlayModule implements ReaderModule {
}
return undefined;
}

myReq;
trackCurrentTime() {
cancelAnimationFrame(this.myReq);
Expand Down Expand Up @@ -377,9 +383,9 @@ export class MediaOverlayModule implements ReaderModule {
this.currentLinkIndex++;
this.playLink();
} else {
this.audioElement?.pause();
this.audioElement.pause();
if (this.settings.autoTurn && this.settings.playing) {
this.audioElement?.pause();
this.audioElement.pause();
this.delegate.nextResource();
} else {
this.stopReadAloud();
Expand Down Expand Up @@ -425,9 +431,9 @@ export class MediaOverlayModule implements ReaderModule {
this.currentLinkIndex++;
this.playLink();
} else {
this.audioElement?.pause();
this.audioElement.pause();
if (this.settings.autoTurn && this.settings.playing) {
this.audioElement?.pause();
this.audioElement.pause();
this.delegate.nextResource();
} else {
this.stopReadAloud();
Expand All @@ -449,7 +455,7 @@ export class MediaOverlayModule implements ReaderModule {
this.mediaOverlayHighlight(undefined);

if (this.audioElement) {
this.audioElement?.pause();
this.audioElement.pause();
}
}
findNextTextAudioPair(
Expand Down Expand Up @@ -645,7 +651,7 @@ export class MediaOverlayModule implements ReaderModule {
) as HTMLAudioElement;

if (this.audioElement) {
this.audioElement?.pause();
this.audioElement.pause();
this.audioElement.setAttribute("src", "");
if (this.audioElement.parentNode) {
this.audioElement.parentNode.removeChild(this.audioElement);
Expand Down Expand Up @@ -699,7 +705,7 @@ export class MediaOverlayModule implements ReaderModule {
await this.playLink();
} else {
if (this.settings.autoTurn && this.settings.playing) {
this.audioElement?.pause();
this.audioElement.pause();
this.delegate.nextResource();
} else {
this.stopReadAloud();
Expand Down Expand Up @@ -765,20 +771,22 @@ export class MediaOverlayModule implements ReaderModule {
this.trackCurrentTime();
};
ensureOnTimeUpdate = (remove: boolean, replace: boolean) => {
if (this.audioElement) {
if (remove) {
if (this.__ontimeupdate) {
this.__ontimeupdate = false;
if (remove) {
if (this.__ontimeupdate) {
this.__ontimeupdate = false;
if (this.audioElement) {
this.audioElement.removeEventListener(
"timeupdate",
this.ontimeupdate
);
cancelAnimationFrame(this.myReq);
}
} else {
if (!this.__ontimeupdate || replace) {
this.__ontimeupdate = true;
if (replace) {
cancelAnimationFrame(this.myReq);
}
} else {
if (!this.__ontimeupdate || replace) {
this.__ontimeupdate = true;
if (replace) {
if (this.audioElement) {
this.audioElement.removeEventListener(
"timeupdate",
this.ontimeupdate
Expand Down

0 comments on commit ec64e08

Please sign in to comment.