2

I need to listen to ready events from a JS object (wavesurfer.js). I initialize the object with:

var wavesurfer = context['WaveSurfer'];

And call its init function with:

wavesurfer.callMethod('init', [mapOptions]);

But I'm unable to listen on ready events like in this JS code:

wavesurfer.on('ready', function () {
   wavesurfer.play();
});

I found solutions for similar problems like here but all are using functions that appear deprecated such as js package's scoped() and Callback.many().

Any pointers are appreciated.

1
  • Could please send me some code snippets of how you implemented wavesurfer-js in Dart, cause I also wanted to display that UI in Flutter Web. Sep 30, 2020 at 6:14

1 Answer 1

4

With dart:js :

wavesurfer.callMethod('on', ['ready', () {
  wavesurfer.callMethod('play');
}]);
4
  • Awesome. This is almost identical to the JS code. I still have this problem though. context['WaveSurfer.Timeline']; should return a JS object after wavesurfer is ready like the JS equivalent Object.create(WaveSurfer.Timeline);. But, it returns null. I have no idea why. I tested the JS equivalent on the same webpage and it works. Feb 2, 2014 at 9:08
  • Does the problem have to do with the way the object is instantiated with the dot in the middle? Feb 2, 2014 at 9:12
  • 1
    You have to use context['WaveSurfer']['Timeline'] to get the equivalent of WaveSurfer.Timeline. Feb 2, 2014 at 9:15
  • Alexandre. You're awesome. Thank you so much for your help. Feb 2, 2014 at 9:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.