dart - 使用 Dart :js to stream audio through the SoundCloud JavaScript API

标签 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' 这也会是有用的信息。

最佳答案

您似乎没有遵循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/

相关文章:

audio - React-sound 在移动设备上不起作用

jquery - 如何通过 SoundCloud API 一次只播放一首歌曲

android - 在 flutter 形式的 sqlite 数据库的 ListView 中加载 7000 多个项目的内存有效方法是什么

java - 使用 soundcloud api 按地理过滤器搜索

python - 如何使用 Python 将文件上传到 Soundcloud?

javascript - 使用 SoundCloud API 暂停声音

javascript - 下一个类的 sibling 不工作

flutter - 没有名称为 'resizeToAvoidBottomPadding' 的命名参数

Flutter Textfield 的高度

flutter - 如何基于Flutter中的X和Y值在ListView或大型Continter中创建动态容器或平面按钮