question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

wavesurfer.backend.getPeaks() returns array with NULL

See original GitHub issue

Hello,

I’m urgently looking for a way to save the waveform on serverside. getPeaks() doesn#t work for me . Any suggestions ? This might be something that should be important in all use cases.

Wavesurfer.js version(s):

2.03

Browser version(s):

Chrome

Code needed to reproduce the issue:

  wavesurfer.on('waveform-ready', function () {
      
                var dataJSON = wavesurfer.backend.getPeaks(960);
                console.log (JSON.stringify(dataJSON));
                var dataImg = wavesurfer.exportImage();
}

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:12

github_iconTop GitHub Comments

2reactions
davidormecommented, Jan 26, 2018

Just to add I was trying to get at the same data and have the same issue using wavesurfer 1.4.0 on both Chrome 63 and Safari 8.0.8 running on Mac 10.10.5. The audio loads and plays as normal.

var dataJSON = wavesurfer.backend.getPeaks(32);
console.log (JSON.stringify(dataJSON));

[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,
 null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,
 null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,
 null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,
 null,null,0,0]
0reactions
claudioemmanuelcommented, Mar 26, 2020

@thijstriemstra even including the minified script: <script src="https://unpkg.com/wavesurfer.js"></script> the problem remains

below is my code where i was returning the audio peaks in an interval, 3 days ago it was working normally, until yesterday it was working normally,

today it just stopped returning some value and is returning an empty array

if i remove the backend option from the setup it does not render my audio on the screen

  var wavesurfer = WaveSurfer.create({
      container: document.querySelector('#waveform'),
      // backend: 'MediaElement',
      waveColor: 'black',
      progressColor: 'gray',
    });

I will explain my application better, I am sending a file through a form so I pass the file (path)

$audio = asset('original/'. $file->getClientOriginalName ());

to the return view

return view ('result')-> with('audio', $audio);

and i’m rendering it this way

  $(document).ready(function() {

    var wavesurfer = WaveSurfer.create({
      container: document.querySelector('#waveform'),
      backend: 'MediaElement',
      waveColor: 'black',
      progressColor: 'gray',
    });

    var audioElement = document.createElement('audio')

    audioElement.autoplay = true
    audioElement.loop = true
    audioElement.crossOrigin = 'anonymous'
    audioElement.src = '{!! $audio !!}'

    wavesurfer.load(audioElement);

    wavesurfer.on('ready', function() {

      var length  = wavesurfer.getDuration();
      var start   = 0;
      var end     = length;

      console.log(wavesurfer.backend.getPeaks(length, start, end));

    });

  });

and in this way, using the backend when creating the WaveSurfer the waves are rendered on screen, if I remove them, the peaks appear but the waves on the screen do not

Read more comments on GitHub >

github_iconTop Results From Across the Web

wavesurfer getPeaks is returning an empty array
It works if you remove this line from the config: backend: 'MediaElement',. Working example: $(document).ready(function() { var wavesurfer ...
Read more >
MediaElement | wavesurfer.js documentation API Document
Returns the current time in seconds relative to the audioclip's duration. ... init(). Initialise the backend, called in wavesurfer.createBackend().
Read more >
src/webaudio.js | wavesurfer.js documentation API Document
* peaks consisting of (max, min) values for each subrange. */; getPeaks(length, first, last) ...
Read more >
src/wavesurfer.js | wavesurfer.js documentation API Document
createBackend ();; this.createPeakCache();; return this;; }; /**; * Add and initialise array of plugins (if `plugin.deferInit` is falsey),; * this function ...
Read more >
src/wavesurfer.js
You have to use the same methods of MediaElement backend for loading and ... with the array of plugin definitions; * @return {this}...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found