About the author

Related Articles

3 Comments

  1. 1
    jblz@email.null'

    jblz

    I’d hope after 5 years this is no longer a problem for you, but I’ve just had to do the same thing. It’s possible using the PyCaw library.

    Simple proof of concept, based on PyCaw’s examples

    from __future__ import print_function
    from pycaw.pycaw import AudioUtilities, ISimpleAudioVolume
    
    
    def main():
        sessions = AudioUtilities.GetAllSessions()
        for session in sessions:
            volume = session._ctl.QueryInterface(ISimpleAudioVolume)
            if session.Process and session.Process.name() == "vlc.exe":
                print("volume.GetMasterVolume(): %s" % volume.GetMasterVolume())
                volume.SetMasterVolume(0.6, None)
    
    
    if __name__ == "__main__":
        main()
    
    Reply
  2. 2
    KodyVanRy@email.null'

    KodyVanRy

    So instead of editing my old answer I’m adding a new post to allow others who use self to use my old code and anyone who’s not, to use my new code.

    def get_master_volume():
        proc = subprocess.Popen('/usr/bin/amixer sget Master', shell=True, stdout=subprocess.PIPE)
        amixer_stdout = proc.communicate()[0].split('n')[4]
        proc.wait()
    
        find_start = amixer_stdout.find('[') + 1
        find_end = amixer_stdout.find('%]', find_start)
    
        return float(amixer_stdout[find_start:find_end])
    
    def set_master_volume(volume):
        val = float(int(volume))
    
        proc = subprocess.Popen('/usr/bin/amixer sset Master ' + str(val) + '%', shell=True, stdout=subprocess.PIPE)
        proc.wait()
    
    Reply
  3. 3
    KodyVanRy@email.null'

    KodyVanRy

    First import subprocess
    import subprocess

    Then to get the master volume

    def get_master_volume(self):
        proc = subprocess.Popen('/usr/bin/amixer sget Master', shell=True, stdout=subprocess.PIPE)
        amixer_stdout = proc.communicate()[0].split('n')[4]
        proc.wait()
    
        find_start = amixer_stdout.find('[') + 1
        find_end = amixer_stdout.find('%]', find_start)
    
        return float(amixer_stdout[find_start:find_end])
    

    And to set the Master volume

    def set_master_volume(self, widget):
        val = self.volume
        val = float(int(val))
        proc = subprocess.Popen('/usr/bin/amixer sset Master ' + str(val) + '%', shell=True, stdout=subprocess.PIPE)
        proc.wait()
    
    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

Copyright © 2017 SolutionMmyself.com