控制Soundcloud HTML5小部件播放器音量

5
我一直在尝试使用Soundcloud博客页面中提供的示例,以便我可以将音量设置得更低。
我只更改了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>

这段代码正在Joomla网站上运行。

有人能帮我理解我缺少了什么来控制音量吗?

是否是jquery冲突导致的?如果是,您对如何解决有什么想法吗?

2个回答

5

实际上,音量范围是从0到1,这在文档中表述错误。因此,如果您想将音量设置为10%,需要使用以下代码:

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

widget.setVolume(0.1);

0

之前的答案已经不准确了。setVolume() API已经被修复/更改为接受0到100之间的整数。

我在尝试使用Chrome控制台快速更改嵌入式SoundCloud iframe的音量时偶然发现了这个问题。我为自己创建了一个快速的gist。 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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接