Using dart:js to stream audio through the SoundCloud JavaScript API


I’m trying to write a library that will make it easer for dartisans to use the SoundCloud JavaScript SDK (

I’m using the ‘dart:js’ library, and
I’m only using one class to handle the proxy.

class SCproxy {
   JsObject proxy = context['SC'];
   String client_id;

SCproxy(this.client_id) {}  

initialize() {
   proxy.callMethod('initialize', [client_id]);
stream(String track_id){
   var track = new JsObject(proxy.callMethod('stream',[track_id]));
   print(track); // track should be the soundmanager2 object that we can call '.play' on.

The repo I’m hosting this from is (

My problem occurs when I try to run my ‘stream’ method.

main() {
   SCproxy SC = new SCproxy('Your SoundCloud API client_ID');

When I try to grab and use the soundmanager2 object returned by the javascript ‘’ method, the dart editor gives me this exception :

Breaking on exception: type 'ScriptElement' is not a subtype of type 'JsFunction' of 'constructor'.

I am under the impression that I should be able to get the dart JsObject for the soundmanager2 object by collecting the callback of the ‘’, But I’m not sure how.However I could be completely misusing ‘dart:js’ and that would be helpful information as well.


You don’t seem to follow the SoundCloud JavaScript SDK documentation. Particularly for the stream method that takes a callback as parameter and doesn’t return.

The following Dart code :

context['SC'].callMethod('stream', ['/tracks/293', (sound) {

will do the same as this JS code :"/tracks/293", function(sound){;

You can have a look at Using JavaScript from Dart for more explanations.

Answered By – Alexandre Ardhuin

Answer Checked By – Katrina (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *