handleEvent(event) { switch (event.type) { case 'timeupdate': store.dispatch(setCurrentTime(event.target.currentTime)); break; case 'ended': store.dispatch(setPlaying(false)); break; default: // Do nothing } }
async loadSound(entry) { if (this.playing) { this.pause(); } if (this.currentSound) { this.currentSound.sourceNode.disconnect(this.gainNode); if (this.currentSound.supportsTime) { this.currentSound.removeListener(this); } } this.currentSound = createSound(entry, this.ctx); await this.currentSound.promiseLoaded; this.currentSound.sourceNode.connect(this.gainNode); if (this.currentSound.supportsTime) { store.dispatch(setDuration(this.currentSound.duration)); this.currentSound.addListener(this); } else { store.dispatch(setCurrentTime(null)); store.dispatch(setDuration(null)); } }