0

I'm using the souncloud api to stream audio from soundcloud. However, I'm trying to get the tracks BPM programmatically so I have the following

Soundcloud.prototype.play = function (options) {
  options = options || {};
  var src;

  if (options.streamUrl) {
    src = options.streamUrl;
  } else if (this._playlist) {
    var length = this._playlist.tracks.length;
    if (length) {
      if (options.playlistIndex === undefined) {
        this._playlistIndex = this._playlistIndex || 0;
      } else {
        this._playlistIndex = options.playlistIndex;
      }

      // be silent if index is out of range
      if (this._playlistIndex >= length || this._playlistIndex < 0) {
        this._playlistIndex = 0;
        return;
      }
      src = this._playlist.tracks[this._playlistIndex].stream_url;
    }
  } else if (this._track) {
    src = this._track.stream_url;
  }

  if (!src) {
    throw new Error('There is no tracks to play, use `streamUrl` option or `load` method');
  }

  if (this._clientId) {
    src = _appendQueryParam(src, 'client_id', this._clientId);
  }

  if (src !== this.audio.src) {
    pulse.loadBufferFromURI(src, (event, pulse) => {
      this.trackBPM = pulse.beat.bpm
      this.audio.src = window.URL.createObjectURL(pulse.renderedBuffer);
      this.playing = src;
      console.log('trackBPM',pulse.beat.bpm);
    })
  } else return this.audio.play();
};

Now

pulse.loadBufferFromURI(src, (event, pulse) => {
          this.trackBPM = pulse.beat.bpm
          this.audio.src = window.URL.createObjectURL(pulse.renderedBuffer);
          this.playing = src;
          console.log('trackBPM',pulse.beat.bpm);
        })

attempts to load the stream_url as aduiobuffer to get the bpm. The question is can I covert the buffer into a source compatible enough to play using <audio> element, reason being I want to take advantage of the event listeners...

Kendall
  • 5,065
  • 10
  • 45
  • 70
  • Possible duplicate of [Loading an Audio buffer and play it using the audio tag](https://stackoverflow.com/questions/14908838/loading-an-audio-buffer-and-play-it-using-the-audio-tag) – zer00ne Apr 07 '18 at 18:32
  • @zer00ne this is not a duplicate. I do not want to use Web Audio API to play audio files. Thanks – Kendall Apr 07 '18 at 23:40
  • Then why do you post a [web-audio-api] tag? Your post title is almost identical to the post I referenced from, plus if your buffer isn't Web Audio, what is it? – zer00ne Apr 08 '18 at 01:38
  • [This](https://stackoverflow.com/questions/29584420/how-to-manipulate-the-contents-of-an-audio-tag-and-create-derivative-audio-tags/30045041#30045041) may help you out if you haven't found a solution already. –  May 01 '18 at 21:24

0 Answers0