2013-12-14 97 views
2

我正在尝试编写一个库,使它能够更好地使用SoundCloud JavaScript SDK(http://developers.soundcloud.com/docs/api/sdks#javascript)。使用dart:js通过SoundCloud JavaScript API流式传输音频

我使用'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

,当我尝试运行我的“流”的方法出现了问题。

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

当我试图抓住并使用由JavaScript“SC.stream”方法返回的soundmanager2对象,飞镖编辑给了我这样的例外:

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

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

+0

是SoundManager2的一个要求吗?如果您只想播放音乐,那么这会带来很多开销。 –

回答

3

你似乎没有按照SoundCloud JavaScript SDK documentation。特别是对于将回调作为参数并且不返回的stream方法。

以下飞镖代码:

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

会做同样的,因为这JS代码:

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

你可以看看Using JavaScript from Dart更多的解释。