Notice: This forum has been recovered from an old backup, so some content, links, and dates may be outdated. The forum is currently read-only while we restore sign-in and registration functionality. Details

If you find this forum valuable and would like to help keep it online, donations to help cover hosting and domain costs are greatly appreciated, but never expected. You can support the forum through Buy Me a Coffee or Ko-fi. Thank you for helping preserve the EventGhost community.

Problem with eg.WinApi.SoundMixer.GetMasterVolume()

If you have a question or need help, this is the place to be.
Post Reply
Smoerebroed
Posts: 2
Joined: Wed May 10, 2017 7:29 am

Problem with eg.WinApi.SoundMixer.GetMasterVolume()

Post by Smoerebroed »

Hey guys,

I am trying to get the current level of my volume on a win 7 32 bit computer and I am struggling with the eg.WinApi.SoundMixer.GetMasterVolume() function.
I have read a lot of threads and could not find any answer to the problem I have. I get an error message that says that there is a problem with the device ID. A screenshot is appended.. I tried a lot of different things to get it work and tried some workarounds but could not figure it out. Hopefully one of you can ;)
Attachments
Error message
Error message
loveleejohn
Experienced User
Posts: 133
Joined: Thu Dec 10, 2015 12:09 am

Re: Problem with eg.WinApi.SoundMixer.GetMasterVolume()

Post by loveleejohn »

Hi there Smorebroed, Sadly I'm not a maverick with the program yet but I have found external posts that may or may have have useful information related to your question. I sure hope these might help at least a bit. https://python-forum.io/Thread-How-to-c ... ith-python http://forums.xkcd.com/viewtopic.php?t=89139 If that doesn't help, hang tight I'm sure someone far more knowledgeable than me will show up to help. :)
User avatar
kgschlosser
Site Admin
Posts: 5190
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Problem with eg.WinApi.SoundMixer.GetMasterVolume()

Post by kgschlosser »

ok quick lesson

if you click on the Help menu then click on python shell...
once the shell opens you will want to type in

Code: Select all

help()
then you will see the help prompt

Code: Select all

help>
once you see that type in

Code: Select all

eg.WinApi.SoundMixer.GetMasterVolume
and press enter.

if there is documentation on the item it will display it. if not it will show you what parameters need to be passed to it.

so in this example this is what is shown. eg.WinApi.SoundMixer.GetMasterVolume = GetMasterVolume(deviceId=0)

we are interested in the goodies between the () which is deviceid=0 so now we know that it takes a parameter that identifies the device. and that the default value is 0 so by not providing an id it will use 0. and apparently you do not have a sound device with the id of 0. so start going through the numbers.

Code: Select all

for i in range(10):
    try:
        volume = eg.WinApi.SoundMixer.GetMasterVolume(i)
        print 'deviceid:', str(i), ' Volume:', str(volume)
    except:
        pass
this will print off the deviceid and the volume if there is a device at that number.. and from there you can do whatever it is you want to do with it. this will only try numbers 0-9

On another note. simply putting the function into a python command even if it did work is not going to do anything for you. you will need to put the value into a variable for later use or print it out.

Code: Select all

eg.result = eg.WinApi.SoundMixer.GetMasterVolume(5)
If you like the work I have been doing then feel free to Image
Smoerebroed
Posts: 2
Joined: Wed May 10, 2017 7:29 am

Re: Problem with eg.WinApi.SoundMixer.GetMasterVolume()

Post by Smoerebroed »

Thanks for your help guys. So what I did is I followed kgschlosser's instruction and to start with I could not get into the "help mode". When I type in help or help() the python shell tells me that the name help is not defined.

But I copied the for loop and extended the search from 0 to 1000. As a result I get that device 0 has a volume of 100. My current volume is somewhere around 20 so not even close to the maximum. I tried to find out my outputs device ID by looking into the device manager which did not help me. (The device name is IDT High Definition Audio CODEC btw and it says path 0 in its properties... )

Is there something wrong with my device maybe? Or the driver?
User avatar
kgschlosser
Site Admin
Posts: 5190
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Problem with eg.WinApi.SoundMixer.GetMasterVolume()

Post by kgschlosser »

ok so this is what we will do to see what is going on.

paste the code below into a python script and run it

Code: Select all

print eg.WinApi.SoundMixer.GetMixerDevices()
it will print into the log something similar to this

{0: u'Speakers (5- High Definition Au', -1: 'Primary Sound Driver'}

if there is more then one device it will appear like so
{0: u'Speakers (5- High Definition Au', -1: 'Primary Sound Driver', 1: u'Second Device Description (5- High Definition Au', -1: 'Primary Sound Driver'}

this is a dict of all of the devices. look for the description of the device you want to get the volume for. you will see a number and a colon right before the description. and that my friend is the device id you will pass to eg.WinApi.SoundMixer.GetMasterVolume()
If you like the work I have been doing then feel free to Image
User avatar
kgschlosser
Site Admin
Posts: 5190
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Problem with eg.WinApi.SoundMixer.GetMasterVolume()

Post by kgschlosser »

Now I went looking and it appears as tho the eg.WinApi.SoundMixer is for pre Windows Vista computers. and VistaVolEvents is for Vista and newer. the reason why the system plugin works properly is because that is where VistaVolEvents has been coded in. So I have changed this and submitted the code changes. Hopefully it will be included in the next release of EG this way no matter what version of Windows you are running eg.WinApi.SoundMixer will function as it should.
If you like the work I have been doing then feel free to Image
User avatar
kgschlosser
Site Admin
Posts: 5190
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Problem with eg.WinApi.SoundMixer.GetMasterVolume()

Post by kgschlosser »

OK the code for the changes to eg.WinApi.SoundMixer automatically running the proper code based on windows version has been added to the Core. so in the next release this will be functioning properly.
If you like the work I have been doing then feel free to Image
Post Reply