Skip to content

Commit

Permalink
fix: add missing event listener
Browse files Browse the repository at this point in the history
  • Loading branch information
riderx committed Jun 7, 2024
1 parent ae232b4 commit 4d1e720
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export class NativeAudioWeb extends WebPlugin implements NativeAudio {
if (Number.isNaN(audio.duration)) {
throw "no duration available";
}
this.notifyListeners;
if (!Number.isFinite(audio.duration)) {
throw "duration not available => media resource is streaming";
}
Expand Down Expand Up @@ -83,12 +84,18 @@ export class NativeAudioWeb extends WebPlugin implements NativeAudio {
new AudioAsset(audio),
);
}
private onEnded(event: Event): void {
const audio: HTMLAudioElement = event.target as HTMLAudioElement;
this.notifyListeners("complete", { assetId: audio.id });
}

async play(options: { assetId: string; time?: number }): Promise<void> {
const audio: HTMLAudioElement = this.getAudioAsset(options.assetId).audio;
await this.stop(options);
audio.loop = false;
audio.currentTime = options.time ?? 0;
audio.removeEventListener("ended", this.onEnded);
audio.addEventListener("ended", this.onEnded);
return audio.play();
}

Expand Down

0 comments on commit 4d1e720

Please sign in to comment.