SoundCloud Widget API setVolume方法坏了吗?

时间:2013-08-20 07:12:59

标签: api methods widget soundcloud

我成功使用了Soundcloud的widget API,但setVolume()方法被破坏了:(

首先,我喜欢这个小部件,但是我很震惊,毕竟那些惊人的工作没有音量控制可用!当听到100%的音频时,人们会立即“退回”我的网站,我无法使用setVolume()改变它...我必须让它工作或拉动它:(

以下是正在发生的事情,我有一个名为“widget”的实例(在页面上加载和播放)。

widget.bind(SC.Widget.Events.READY, function() {
    $('#audioIndictments').removeClass('remove');  // This disables a CSS rule, making the soundCloud iframe visible

    widget.setVolume(10);  //  This should set the volume to 10% but doesn't :(
    widget.getVolume(function(vol){
        console.log(vol);  // This outputs 0.1 in the console :/
        console.log(widget);  // This outputs the object in the console and I don't see anything out of whack :|
    });

    widget.play();  // This successfully fires up the widget and the audio begins playing :)
    widget.setVolume(10);  // Just to see if it makes a difference, after the play() method, I ran setVolume again after the play() method and still no change :(

    widget.getVolume(function(vol){
        console.log(vol);  // This still outputs 0.1 in the console :/
    });
});

奇怪的结果。我发现另一位博客提出了类似的问题但得不到满意的答案。这是什么交易?我没看到什么?

感谢您抽出宝贵时间:)

2 个答案:

答案 0 :(得分:5)

尝试使用介于0和1之间的音量。这为我修复了它。

0.25 = 25%体积

答案 1 :(得分:3)

我也面临同样的问题,我发现在READY事件之外调用setVolume方法时,音量不会重置为完全。这就是为什么SC api操场上的setVolume按钮可以工作,因为它是从外部调用的。但是还有另一个问题 - 当播放列表中的下一首曲目加载到小部件中时,它会将音量重置为完全,从而使用户震耳欲聋。

我已经使用了一个hacky解决方法,直到修复完毕。

设置一个新的PLAY_PROGRESS事件并调用其中的方法。

widget.bind(SC.Widget.Events.PLAY_PROGRESS, function() {
widget.setVolume(10);
});

播放曲目时将连续调用setVolume方法。不理想,但它有效。

如果您有适合音量的滑块,那么您可以改为使用它:

widget.bind(SC.Widget.Events.PLAY_PROGRESS, function() {
var vol = jQuery('.slider').val();
widget.setVolume(vol);
});