question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error when using pycaw with Ctypes

See original GitHub issue

Hi, I get the following error when using the function AudioUtilities.GetAllDevices(). Seems to be an issue with ctypes. It works on my other machine, but this particular laptop does not like it. Any ideas as to how to resolve this issue?

Running Windows10 Python 2.7.3 64 bit

error:

Traceback (most recent call last):
  File "mvol.py", line 13, in <module>
    devices = AudioUtilities.GetAllDevices()
  File "C:\python_27_amd64\files\lib\site-packages\pycaw\pycaw.py", line 701, in GetAllDevices
    devices.append(AudioUtilities.CreateDevice(dev))
  File "C:\python_27_amd64\files\lib\site-packages\pycaw\pycaw.py", line 673, in CreateDevice
    value = store.GetValue(pk)
_ctypes.COMError: (-536870389, None, (None, None, None, 0, None))

Here is the snippet of code that I am running:

from ctypes import cast, POINTER
from comtypes import CLSCTX_ALL
from pycaw.pycaw import AudioUtilities, IAudioEndpointVolume
devices = AudioUtilities.GetSpeakers()
interface = devices.Activate(
    IAudioEndpointVolume._iid_, CLSCTX_ALL, None)
volume = cast(interface, POINTER(IAudioEndpointVolume))
print(volume.GetMute())
print(volume.GetMasterVolumeLevel())
print(volume.GetVolumeRange())
volume.SetMasterVolumeLevel(-20.0, None)

devices = AudioUtilities.GetAllDevices()
for d in devices:
  print(str(d) + " " + str(d.state))

Let me know if I can try something to test, or if you need additional info.

Make sure to give enough information to help debugging your issue. Here are some hints:

  • current requirements (pip freeze)
  • OS version
  • architecture
  • Python version
  • pycaw version
  • project files
  • exact stacktrace / accurate error message
  • and so on

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
riti044commented, Nov 9, 2021

cn u pls pls pls pls pls make it for mac 😦

0reactions
riti044commented, Nov 9, 2021

ahh cn u pls tell me what it is

Read more comments on GitHub >

github_iconTop Results From Across the Web

SyntaxError: multiple exception types must be parenthesized
I am a beginner and have a problem after installing pycaw for the audio control using python, on putting the basic ...
Read more >
pycaw-rf · PyPI
Python Core Audio Windows Library, working for both Python2 and Python3. Install. Latest stable release: pip install pycaw. Development branch:
Read more >
ctypes cast and from_address cause crash on Windows 10
Hi, Using cast() or from_address() to convert from c_void_p (or ... #arr = POINTER(c_ubyte).from_address(ptr) arr[0] # now crashes ``` Also ...
Read more >
Windows Archive - TechOverflow -
You see an error message like the following one when running some Python code ... We can use the pycaw library to set...
Read more >
Creating a Hand Gesture Volume Controller using Python and ...
pycaw depends on these two libraries. Ctypes provides C language compatible data types. Comtypes bases on the ctypes FFI(Foreign Function ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found