我正在尝试编写一个库,使 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' 这也会是有用的信息。
最佳答案
您似乎没有遵循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了解更多解释。
关于dart - 使用 Dart :js to stream audio through the SoundCloud JavaScript API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20585852/