onPlayRecordingClick()

in client/src/components/add-word-fieldset/add-word-fieldset.ts [138:178]


  onPlayRecordingClick(ev: MouseEvent) {
    ev.preventDefault();
    ev.stopPropagation();
    logger.log('Starting playback');
    if (!this.recording) {
      logger.warn('No audio recorded');
      alert('no audio');
      return false;
    }
    this.audioStreamProgress = 0;
    this.recordingState = RecordingState.Playing;
    play(this.recording).then(
      (stream) => {
        logger.log('Playback started');
        this.audioStream = stream;
        const progressInterval = setInterval(() => {
          this.zone.run(() => {
            let duration = stream.getDuration();
            if (!Number.isFinite(duration)) {
              duration = this.config.maxRecordingDuration * 0.001;
            }
            this.audioStreamProgress = stream.getCurrentTime() / duration;
          });
        }, this.config.progressAnimationInterval);
        stream.onended = () => {
          logger.log('Playback ended');
          clearInterval(progressInterval);
          this.zone.run(() => {
            this.recordingState = RecordingState.Finished;
          });
        };
      },
      (err) => {
        logger.warn('Error playing recording', err);
        alert(err);
        this.zone.run(() => {
          this.recordingState = RecordingState.Finished;
        });
      }
    );
  }