使用dart:js通过SoundCloud JavaScript API流式传输音频

时间:2013-12-14 16:57:52

标签: dart soundcloud soundmanager2 dart-js-interop

我正在尝试编写一个库,使dartisans更容易使用SoundCloud JavaScript SDK(http://developers.soundcloud.com/docs/api/sdks#javascript)。

我正在使用'dart:js'库,而且 我只使用一个类来处理代理。

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.
}

我主持的回购是(https://github.com/darkkiero/scproxy

当我尝试运行'stream'方法时,会出现问题。

main() {
   SCproxy SC = new SCproxy('Your SoundCloud API client_ID');
   SC.initialize();
   SC.stream('/tracks/111477464'); 
}

当我尝试抓取并使用javascript'SC.stream'方法返回的soundmanager2对象时,dart编辑器给了我这个例外:

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

我的印象是我应该能够通过收集'SC.stream'的回调来获取soundmanager2对象的dart JsObject,但我不确定如何。但是我可能完全滥用'dart :js',这也是有用的信息。

1 个答案:

答案 0 :(得分:3)

您似乎没有关注SoundCloud JavaScript SDK documentation。特别是对于将回调作为参数而不返回的stream方法。

以下Dart代码:

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

将与此JS代码相同:

SC.stream("/tracks/293", function(sound){
  sound.play();
});

您可以查看Using JavaScript from Dart以获取更多解释。