Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement RegisterAudioSessionNotification #27

Open
ColCh opened this issue Jan 2, 2021 · 4 comments
Open

Implement RegisterAudioSessionNotification #27

ColCh opened this issue Jan 2, 2021 · 4 comments

Comments

@ColCh
Copy link

ColCh commented Jan 2, 2021

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

currently, it stays unimplemented

link to docs: https://docs.microsoft.com/en-us/windows/win32/api/audiopolicy/nf-audiopolicy-iaudiosessioncontrol-registeraudiosessionnotification

pycaw/pycaw/pycaw.py

Lines 256 to 260 in f7bd1a9

# HRESULT RegisterAudioSessionNotification(
# [in] IAudioSessionEvents *NewNotifications);
COMMETHOD([], HRESULT, 'NotImpl7'),
# HRESULT UnregisterAudioSessionNotification(
# [in] IAudioSessionEvents *NewNotifications);

Without this thing, it's impossible to listen upon audio session volume change :(

@AndreMiras
Copy link
Owner

Thanks for the report, maybe you could try your luck making a pull request implementing it 😉

@luluu9
Copy link

luluu9 commented Apr 1, 2021

Hello, I'm trying to implement this functionality, but I've got some problems which I can't solve myself.
I've made IAudioSessionEvents class:

class IAudioSessionEvents(IUnknown): # https://docs.microsoft.com/en-us/windows/win32/coreaudio/audio-session-events
    _iid_ = GUID('{b1136c83-b6b5-4add-98a5-a2df8eedf6fc}')
    _methods_ = (
        # HRESULT OnSimpleVolumeChanged(
        # [in] float   NewVolume,
        # [in] BOOL    NewMute,
        # [in] LPCGUID EventContext);
        COMMETHOD([], HRESULT, 'OnSimpleVolumeChanged',
            (['in'], c_float, 'NewVolume'),
            (['in'], DWORD, 'NewMute'),
            (['in'], POINTER(GUID), 'EventContext')),
    )

and implemented Register and Unregister Audio Session Notification methods:

        # HRESULT RegisterAudioSessionNotification(
        # [in] IAudioSessionEvents *NewNotifications);
        COMMETHOD([], HRESULT, 'RegisterAudioSessionNotification',
                 (['in'], POINTER(IAudioSessionEvents), 'NewNotifications')),
        # HRESULT UnregisterAudioSessionNotification(
        # [in] IAudioSessionEvents *NewNotifications);
        COMMETHOD([], HRESULT, 'UnregisterAudioSessionNotification',
                 (['in'], POINTER(IAudioSessionEvents), 'NewNotifications')))

Taking as an example class AudioEndpointVolumeCallback(COMObject), I've created AudioSessionEvents:

class AudioSessionEvents(COMObject):
    _com_interfaces_ = [IAudioSessionEvents]

    def OnSimpleVolumeChanged(self, *args, **kwargs):
        print('OnSimpleVolumeChanged event')

I had thought everything was fine, but when I tried this code:

    callback = AudioSessionEvents()
    sessions = AudioUtilities.GetAllSessions()
    for session in sessions:
        session._ctl.RegisterAudioSessionNotification(callback)
        volume = session.SimpleAudioVolume
        print("volume.GetMute(): %s" % volume.GetMute())
        volume.SetMute(1, None)

there is no "OnSimpleVolumeChanged event" message.
Could someone guide me what is wrong?

@TurboAnonym
Copy link
Contributor

Thats all what i could collect on this topic:

https://github.com/TurboAnonym/pycaw/tree/develop/IAudioSessionEvents

I made the nessesary changes in my pycaw.pycaw file in line 236 and 280

@luluu9

    COMMETHOD([], HRESULT, 'OnSimpleVolumeChanged',
        (['in'], c_float, 'NewVolume'),
        (['in'], DWORD, 'NewMute'),   <- shouldnt be that BOOL instead of DWORD?
        (['in'], POINTER(GUID), 'EventContext')),

@TurboAnonym
Copy link
Contributor

@ColCh and @luluu9 good news everyone ;)
I successfully implemented it! (After a long long time xD)
#36

@luluu9 the problem was, that there where no dummy COMMETHODs like for OnIconPathChanged or the others ; )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants