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.

POINTER(IAudioSessionControl2)' object has no attribute 'GetState‘

See original GitHub issue

code:

from pycaw.pycaw import AudioUtilities
import time


def main():
    while True:
        sessions = AudioUtilities.GetAllSessions()
        for session in sessions:
            if session.Process and session.InstanceIdentifier.find("foobar") >= 0:
                print(session.InstanceIdentifier)
                print(session.State)

        time.sleep(1)

if __name__ == "__main__":
    main()

error:

{0.0.0.00000000}.{03b51635-f342-4dcd-b24d-c459985d9f01}|#%b{0B9C664C-1049-4DB7-8104-97016411F561}|1%b#
Traceback (most recent call last):
  File "D:/code/pystream/device.py", line 17, in <module>
    main()
  File "D:/code/pystream/device.py", line 12, in main
    print(session.State)
  File "D:\anaconda3\envs\pystream32\lib\site-packages\pycaw\pycaw.py", line 608, in State
    s = self._ctl.GetState()
AttributeError: 'POINTER(IAudioSessionControl2)' object has no attribute 'GetState'

https://docs.microsoft.com/en-us/windows/win32/api/audiopolicy/nn-audiopolicy-iaudiosessioncontrol2 The IAudioSessionControl2 interface inherits from IAudioSessionControl. I need to use getstate method,what should I do? https://docs.microsoft.com/en-us/windows/win32/api/audiopolicy/nf-audiopolicy-iaudiosessioncontrol-getstate

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
TurboAnonymcommented, Apr 24, 2021
1reaction
TurboAnonymcommented, Apr 24, 2021

Hi @zhjy8827 😉 I will make a pull request later but a quick fix for now is replacing this code from the pycaw.pycaw file: (your pycaw location: “D:\anaconda3\envs\pystream32\lib\site-packages\pycaw\pycaw.py”)

class IAudioSessionControl(IUnknown):
    _iid_ = GUID('{F4B1A599-7266-4319-A8CA-E70ACB11E8CD}')
    _methods_ = (
        # HRESULT GetState ([out] AudioSessionState *pRetVal);
        COMMETHOD([], HRESULT, 'NotImpl1'),

with the following:

class IAudioSessionControl(IUnknown):
    _iid_ = GUID('{F4B1A599-7266-4319-A8CA-E70ACB11E8CD}')
    _methods_ = (
        # HRESULT GetState ([out] AudioSessionState *pRetVal);
        COMMETHOD([], HRESULT, 'GetState',
                  (['out'], POINTER(DWORD), 'pRetVal')),

After that session.State will return an int: 0 = AudioSessionStateInactive 1 = AudioSessionStateActive 2 = AudioSessionStateExpired

Read more comments on GitHub >

github_iconTop Results From Across the Web

"AttributeError: 'module' object has no attribute '__getstate__ ...
AttributeError : 'module' object has no attribute '__getstate__'. I'm using setuptools-0.6c11-py2.6. python · django · easy-install.
Read more >
IAudioSessionControl::GetState (audiopolicy.h) - Win32 apps
Pointer to a variable into which the method writes the current session state. The state must be one of the following AudioSessionState ...
Read more >
Code - e7devteam/Rhythm-Breaker - Yona
Object @)"> <summary> Retrieves an interface pointer associated with a key. </summary> </member> <member name="M:NAudio.MediaFoundation.IMFAttributes.
Read more >
API Document | PDF | Microsoft Windows - Scribd
sIDHistory attribute of a security principal in another domain ... object creation extension with a pointer to the directory object created.
Read more >
Diff - wine-1.3.20 - Git repositories on goma
user32: Only call the driver when the cursor position has really changed. ... + mmdevapi/tests: Add tests for IAudioSessionControl::GetState.
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