1

I want to use setVolume(0.01) on SoundCloud because it's way to loud for me. As a temporary solution, I made the whole Chrome browser quieter, but then Youtube and other websites are too quiet.

I found that SoundCloud's volume can be controlled via the "SC.Widget method", but I have no idea what that is.

Can somebody explain how I can use that to set SoundCloud's volume to 0.01?

I already tried to put that just in the Chrome console but this gives me the following: VM1394:1 Uncaught ReferenceError: setVolume is not defined(…)

chrki
  • 6,143
  • 6
  • 35
  • 55

2 Answers2

2

To change the volume on the Soundcloud website with a script there's no real API you can use, and no official way to do so. This should work:

webpackJsonp([], {
    0: function(a, b, require) {
        var modules = require.c;
        modules[54].exports.broadcast("volume:set", 0.1);
    }
});

Because the Soundcloude code is minified and not made to be used by other scripts, it is possible that the above solution might break with an error like this:

Uncaught TypeError: modules[54].exports.broadcast is not a function(…)

A hacky solution is to iterate over all modules and execute the volume:set broadcast:

webpackJsonp([], {
    0: function(a, b, require) {
        var modules = require.c;
        for(var x in modules){
            if(modules[x].exports.broadcast){
                modules[x].exports.broadcast("volume:set", 1.0);
            }
        }
    }
});

To change volume on Soundcloud widgets:

The HTML5 widget API is explained here. What you need to do first is include Soundcloud's API script, you can use this code which I borrowed from here:

var scapi = document.createElement('script');
scapi.src = "https://w.soundcloud.com/player/api.js";
document.getElementsByTagName('head')[0].appendChild(scapi);

The next step is finding the Soundcloud widget and use the API script to get the functionality we need, i.e. setVolume():

var sciframe = document.querySelector("iframe");
var widget = SC.Widget(sciframe);
widget.setVolume(0.1); // goes from 0 to 1

This you can use as a userscript with Greasemonkey or Tampermonkey and run it automatically:

var scapi = document.createElement('script');
scapi.src = "https://w.soundcloud.com/player/api.js";
document.getElementsByTagName('head')[0].appendChild(scapi);

function waitAndRegister() {
    window.setTimeout(function(){ 
    if(typeof(SC) == 'undefined') { 
            waitAndRegister();
        } else {
            quiet();
        }
    }, 100);
};
waitAndRegister();

function quiet() {
    var scWidgets = document.querySelectorAll('iframe[src^="https://w.soundcloud.com/player"]');
    if(scWidgets.length > 0) {
      for (var i = 0; i < scWidgets.length; ++i) {
        var widget = SC.Widget(scWidgets[i]);
        widget.bind(SC.Widget.Events.PLAY, function() {
          widget.setVolume(0.1);
        });
      }
    }
}
Community
  • 1
  • 1
chrki
  • 6,143
  • 6
  • 35
  • 55
  • Unfortunately that doesn't work, TamperMonkey shows the script is activated, but the volume doesn't change. – lemon126491 May 16 '16 at 20:09
  • Do you have a link that I can test? – chrki May 16 '16 at 20:13
  • what link? soundcloud.com? – lemon126491 May 16 '16 at 22:23
  • @lemon126491 The site where you are experiencing issues with widgets and my script, if you don't mind sharing that – chrki May 17 '16 at 09:00
  • @lemon126491 Oh then I misunderstood your question, i thought you meant other websites that use Soundcloud because you mentioned "widgets". See my edit on the top – chrki May 18 '16 at 05:24
  • hi :) that versions doesn't work anymore.. VM136:4 Uncaught TypeError: modules[23].exports.broadcast is not a function(…) – lemon126491 Jun 13 '16 at 21:54
  • @lemon126491 The module number changed from 23 to 54. That's the issue with the website, it's minified and mostly unreadable code, hard to figure out and constantly changing, and there's no official way to use it programmatically :/ – chrki Jun 14 '16 at 05:51
  • thanks! and how did you get that? then i dont have to ask you next time – lemon126491 Jun 14 '16 at 17:18
0

Chrome > ctrl+shift+i > Application Tab > Storage > Local Storage > V2::local::settings

and set volume you need (eg: volume":0.05,")

Works like a charm for me.

1337
  • 1