【问题标题】:Controlling Soundcloud HTML5 Widget Player Volume控制 Soundcloud HTML5 小部件播放器音量
【发布时间】:2012-09-04 22:55:41
【问题描述】:

我一直在尝试使用a Soundcloud Blog page 上给出的示例,以便将音量调低。

我只将iframe 的大小和src= 更改为我的播放列表并将音量设置为10,这样我就可以注意到它是否有效。到目前为止,我没有观察到任何变化,音量仍然是 100%。

我已经尝试过,无论是否将以下内容放在我的模板头部。好像没关系。

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>

这是我根据 Soundcloud 示例调整的代码:

    <iframe id="sc-widget" width="350" height="332" scrolling="no" frameborder="no" src="http://w.soundcloud.com/player/?url=http%3A%2F%2Fapi.soundcloud.com%2Fplaylists%2F1417174&auto_play=true&show_artwork=false&color=37415f"></iframe>

  <script src="http://w.soundcloud.com/player/api.js" type="text/javascript"></script>
  <script type="text/javascript">
  (function(){
    var widgetIframe = document.getElementById('sc-widget'),
        widget       = SC.Widget(widgetIframe);

    widget.bind(SC.Widget.Events.READY, function() {
      widget.bind(SC.Widget.Events.PLAY, function() {
        // get information about currently playing sound
        widget.getCurrentSound(function(currentSound) { 
          console.log('sound ' + currentSound.get('') + 'began to play');
        });
      });
      // get current level of volume
      widget.getVolume(function(volume) {
        console.log('current volume value is ' + volume);
      });
      // set new volume level
      widget.setVolume(10);
    });

  }());
  </script>

This code is live on a Joomla site.

有人可以帮我了解我在控制音量方面缺少什么吗?

是jquery冲突吗?如果是这样,有什么想法可以解决吗?

【问题讨论】:

    标签: html html5-audio soundcloud volume web-widget


    【解决方案1】:

    音量范围实际上是从 0 到 1,这在文档中是错误的。因此,如果您想将音量设置为 10%,您需要这样:

    var widgetIframe = document.getElementById('sc-widget'),
    widget       = SC.Widget(widgetIframe);
    
    widget.setVolume(0.1);
    

    【讨论】:

      【解决方案2】:

      之前的答案不再准确。 setVolume() api 已修复/更改为接受 0 到 100 之间的 int。

      我偶然发现了这个问题,试图使用 chrome 控制台快速更改嵌入式 SoundCloud iframe 的音量。我为自己创建了一个快速要点。 https://gist.github.com/propagated/78aaedfbc0c23add7691bb975b51a3ff

      //load soundcloud js api if needed
      var script = document.createElement('script');
      script.type = 'text/javascript';
      script.src = 'http://w.soundcloud.com/player/api.js';
      document.head.appendChild(script);
      
      //get the id of the player iframe or inject it using chrome
      var id = 'scplayer',
          widgetIframe = document.getElementById(id),
          fixWidget = SC.Widget(widgetIframe);
      fixWidget.setVolume(50); //% between 1 and 100
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多