3

我成功地使用了 Soundcloud 的小部件 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 :/
    });
});

奇怪的结果。我找到了另一个博主,他问了一个类似的问题,但没有得到满意的答案。这是怎么回事?我没看到什么?

感谢您抽出宝贵时间:)

4

2 回答 2

4

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

0.25 = 25% 体积

于 2014-08-20T16:15:18.493 回答
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);
});
于 2013-11-29T15:22:19.583 回答