使用自定义按钮控制Soundcloud HTML5 Widget Player

时间:2012-07-13 23:50:58

标签: javascript custom-controls soundcloud

我想做类似于我在SoundClouds HTML5 Widget API PLayground页面上看到的内容,它们有控制播放器的外部按钮: http://w.soundcloud.com/player/api_playground.html

最终我将隐藏播放器小部件并将这些按钮用作音乐控制器。

任何建议或提示都很棒,我在此处发布:http://jsfiddle.net/alexsethalex/qcKed/1/

1 个答案:

答案 0 :(得分:14)

你签出了Widget API documentation吗?

这是一个非常简单的例子:

<!doctype html>
<html>
<head>
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
  <script src="http://w.soundcloud.com/player/api.js"></script>
  <script>
   $(document).ready(function() {
     var widget = SC.Widget(document.getElementById('soundcloud_widget'));
     widget.bind(SC.Widget.Events.READY, function() {
       console.log('Ready...');
     });
     $('button').click(function() {
       widget.toggle();
     });
   });
  </script>
</head>
<body>
  <iframe id="soundcloud_widget"
      src="http://w.soundcloud.com/player/?url=https://api.soundcloud.com/tracks/39804767&show_artwork=false&liking=false&sharing=false&auto_play=true"
      width="420"
      height="120"
      frameborder="no"></iframe>
  <button>Play / Pause</button>
</body>
</html>