简体   繁体   English

控制Soundcloud HTML5 Widget Player音量

[英]Controlling Soundcloud HTML5 Widget Player Volume

I have been attempting to use the example given on a Soundcloud Blog page so I can set the volume lower. 我一直在尝试使用Soundcloud博客页面上给出的示例,以便可以将音量调低。

I only changed the iframe size and src= to my playlist and set volume to 10 so I could notice the difference if it worked. 我只将iframe大小和src=更改为播放列表,并将音量设置为10,这样我就可以注意到其中的区别。 So far I observe no change, volume is still at 100%. 到目前为止,我没有发现任何变化,音量仍为100%。

I have tried it with and without placing the following in the head of my template. 我尝试过并且没有在模板的开头放置以下内容。 It doesn't seem to matter. 似乎无关紧要。

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

Here is the code that I adjusted from the Soundcloud example: 这是我从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. 此代码位于Joomla网站上。

Can someone please help me understand what I'm lacking to control the volume? 有人可以帮我了解我控制音量不足的地方吗?

Is it a jquery conflict? 它是jquery冲突吗? If so, any thoughts on how to resolve it? 如果是这样,对如何解决有什么想法?

the volume range is actually from 0 to 1, this is stated wrongly in the documentation. 音量范围实际上是从0到1,这在文档中有误。 So if you would like to set the volume to 10%, you would need this: 因此,如果要将音量设置为10%,则需要这样做:

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

widget.setVolume(0.1);

The previous answer is no longer accurate. 先前的答案不再准确。 The setVolume() api has been fixed/changed to take in an int between 0 and 100. setVolume()API已修复/更改为采用0到100之间的整数。

I stumbled upon this question trying to quickly change the volume of an embedded SoundCloud iframe using the chrome console. 我偶然发现了这个问题,试图使用chrome控制台快速更改嵌入式SoundCloud iframe的音量。 I created a quick gist for myself. 我为自己创建了一个要点。 https://gist.github.com/propagated/78aaedfbc0c23add7691bb975b51a3ff 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM