Как отследить загрузку Blob аудио-файла в Howler js

Рейтинг: 0Ответов: 0Опубликовано: 03.02.2023

Мне с сервера приходит список полей. Среди них mp3 файл в виде текста (напр: '1.mp3'). При нажатии на play этот '1.mp3' улетает на сервер и возвращает Blob blob:http://localhost:4200/6ffb741d-2d71-4bba-a96d-88da112005f9, сразу прогружается!, а мне бы хотелось отследить предзагрузку и получить данные о длине трека заранее: введите сюда описание изображения

Я использую библиотеку Howler Js. Мой код:

public getBlob(e, cellData): null | void {
    this.trackIsLoad = true;
    if (this.sound?.playing() === undefined || this.currentId !== cellData.data.id) {

      this.sound?.unload();

      this.service.getCallFile(e).subscribe(blob => {

        this.currentId = cellData.key;

        this.sound = new Howl({
          src: [URL.createObjectURL(blob)],
          preload: true,
          html5: true,
          onplay: () => {
            // Display the duration.
            this.paused = false;
            this.trackIsLoad = false;
            this.duration = this.formatTime(Math.round(this.sound.duration()));

            // старт обновления информации о ходе прогресса трека
            requestAnimationFrame(this.step.bind(this));
          },
          onseek: () => {
            requestAnimationFrame(this.step.bind(this));
          },
          onpause: () => {
            this.trackIsLoad = false;
            requestAnimationFrame(this.step.bind(this));
          },
          onend: () => {
            this.paused = true;
          }
        });
        this.sound.play();
        this.sound.on('load', this.handleLoad);
      });
      return;
    }
    if (this.paused) {
      this.sound.play();
      return;
    }
    if (this.sound?.playing()) {
      this.sound.pause();
      this.paused = true;
    }
  }

Есть ли возможность реализовать это?

Ответы

Ответов пока нет.