Jump to content
Sign in to follow this  
nacerbaaziz

Detect if the audio output is changed

Recommended Posts

Hello my friends
I have an urgent problem and we hope you can help me
I want to detect if the audio output of the device has changed
Such as the headset is connected or disConnected.
or change the default audio output
Is this possible?
I really searched a lot and found suggestions but unfortunately I did not understand them
Please explain to me
Greetings

Share this post


Link to post
Share on other sites

Um, I see that you haven't given enough detail in what approaches you have already taken and researched. This may be difficult for a blind person.

How about some code for what you already have done in this 'urgent' problem?

Is this related to the other post you made at https://www.autoitscript.com/forum/topic/189645-an-important-question-in-the-bassdll-file/ ?

Would the condensed summary of AutoIt at https://github.com/J2TeaM/awesome-AutoIt be of assistance?

Edited by Confuzzled

Share this post


Link to post
Share on other sites
; _IMMNotificationClient

; By KaFu, based on this example by trancexx
; http://www.autoitscript.com/forum/topic/151474-looking-to-capture-immnotificationclientondevicestatechanged-events/#entry1084193


Global $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc")
Func _ErrFunc($oError)
    ConsoleWrite("COM Error, ScriptLine(" & $oError.scriptline & ") : Number 0x" & Hex($oError.number, 8) & " - " & $oError.windescription & @CRLF)
EndFunc   ;==>_ErrFunc


; Global Const $sIID_IMMNotificationClient = "{7991EEC9-7E89-4D85-8390-6C703CEC60C0}"
Global Const $tagIMMNotificationClient = "OnDeviceStateChanged hresult(wstr;dword);" & _
        "OnDeviceAdded hresult(wstr);" & _
        "OnDeviceRemoved hresult(wstr);" & _
        "OnDefaultDeviceChanged hresult(dword;dword;wstr);" & _
        "OnPropertyValueChanged hresult(wstr;int64);" ; last param type is improvisation because AutoIt lacks proper type

Func _IMMNotificationClient_OnDeviceStateChanged($hresult, $wstr, $dword)
    #forceref $hresult
    ConsoleWrite("_IMMNotificationClient_OnDeviceStateChanged" & @TAB & $wstr & @TAB & $dword & @CRLF)
    Return 0 ; S_OK
EndFunc   ;==>_IMMNotificationClient_OnDeviceStateChanged

Func _IMMNotificationClient_OnDeviceAdded($hresult, $wstr)
    #forceref $hresult
    ConsoleWrite("_IMMNotificationClient_OnDeviceAdded" & @TAB & $wstr & @CRLF)
    Return 0 ; S_OK
EndFunc   ;==>_IMMNotificationClient_OnDeviceAdded

Func _IMMNotificationClient_OnDeviceRemoved($hresult, $wstr)
    #forceref $hresult
    ConsoleWrite("_IMMNotificationClient_OnDeviceRemoved" & @TAB & $wstr & @CRLF)
    Return 0 ; S_OK
EndFunc   ;==>_IMMNotificationClient_OnDeviceRemoved

Func _IMMNotificationClient_OnDefaultDeviceChanged($hresult, $dword1, $dword2, $wstr)
    #forceref $hresult
    ConsoleWrite("_IMMNotificationClient_OnDefaultDeviceChanged" & @TAB & $dword1 & @TAB & $dword2 & @TAB & $wstr & @CRLF)
    Return 0 ; S_OK
EndFunc   ;==>_IMMNotificationClient_OnDefaultDeviceChanged

Func _IMMNotificationClient_OnPropertyValueChanged($hresult, $wstr, $int64)
    #forceref $hresult
    ConsoleWrite("_IMMNotificationClient_OnPropertyValueChanged" & @TAB & $wstr & @TAB & $int64 & @CRLF)
    Return 0 ; S_OK
EndFunc   ;==>_IMMNotificationClient_OnPropertyValueChanged

#cs
    Global Const $sIID_IUnknown = "{00000000-0000-0000-C000-000000000046}"
    Global Const $tagMyInterface = "FirstMethod hresult(wstr);" & _
    "SecondMethod hresult(int;wstr);"
#ce

Global $t_IMMNotificationClient
Global $o_IMMNotificationClient = ObjectFromDtag("_IMMNotificationClient_", $tagIMMNotificationClient, $t_IMMNotificationClient)
; Global $p_IMMNotificationClient = ptr($o_IMMNotificationClient())
Global $p_IMMNotificationClient = $o_IMMNotificationClient()

#cs
    ; Is object get?
    ConsoleWrite("!!! IsObj($oMyObject) = " & IsObj($o_IMMNotificationClient) & @CRLF)
    $o_IMMNotificationClient.OnDeviceRemoved("Test")
    ; Get object pointer:
    ConsoleWrite("+>>> Object pointer = " & $o_IMMNotificationClient() & @CRLF)
#ce

Func ObjectFromDtag($sFunctionPrefix, $tagInterface, ByRef $tInterface)
    Local Const $tagIUnknown = "QueryInterface hresult(ptr;ptr*);" & _
            "AddRef dword();" & _
            "Release dword();"
    ; Adding IUnknown methods
    $tagInterface = $tagIUnknown & $tagInterface
    Local Const $PTR_SIZE = DllStructGetSize(DllStructCreate("ptr"))
    ; Below line really simple even though it looks super complex. It's just written weird to fit one line, not to steal your eyes
    Local $aMethods = StringSplit(StringReplace(StringReplace(StringReplace(StringReplace(StringTrimRight(StringReplace(StringRegExpReplace($tagInterface, "\h*(\w+)\h*(\w+\*?)\h*(\((.*?)\))\h*(;|;*\z)", "$1\|$2;$4" & @LF), ";" & @LF, @LF), 1), "object", "idispatch"), "variant*", "ptr"), "hresult", "long"), "bstr", "ptr"), @LF, 3)
    Local $iUbound = UBound($aMethods)
    Local $sMethod, $aSplit, $sNamePart, $aTagPart, $sTagPart, $sRet, $sParams
    ; Allocation. Read http://msdn.microsoft.com/en-us/library/ms810466.aspx to see why like this (object + methods):
    $tInterface = DllStructCreate("ptr[" & $iUbound + 1 & "]")
    If @error Then Return SetError(1, 0, 0)
    For $i = 0 To $iUbound - 1
        $aSplit = StringSplit($aMethods[$i], "|", 2)
        If UBound($aSplit) <> 2 Then ReDim $aSplit[2]
        $sNamePart = $aSplit[0]
        $sTagPart = $aSplit[1]
        $sMethod = $sFunctionPrefix & $sNamePart
        $aTagPart = StringSplit($sTagPart, ";", 2)
        $sRet = $aTagPart[0]
        $sParams = StringReplace($sTagPart, $sRet, "", 1)
        $sParams = "ptr" & $sParams
        DllStructSetData($tInterface, 1, DllCallbackGetPtr(DllCallbackRegister($sMethod, $sRet, $sParams)), $i + 2) ; Freeing is left to AutoIt.
    Next
    DllStructSetData($tInterface, 1, DllStructGetPtr($tInterface) + $PTR_SIZE) ; Interface method pointers are actually pointer size away
    Return ObjCreateInterface(DllStructGetPtr($tInterface), "", $tagInterface, False) ; and first pointer is object pointer that's wrapped
EndFunc   ;==>ObjectFromDtag



Global Const $sCLSID_MMDeviceEnumerator = "{BCDE0395-E52F-467C-8E3D-C4579291692E}"
Global Const $sIID_IMMDeviceEnumerator = "{A95664D2-9614-4F35-A746-DE8DB63617E6}"

Global Const $tagIMMDeviceEnumerator = "EnumAudioEndpoints hresult(dword;dword;ptr*);" & _
        "GetDefaultAudioEndpoint hresult(dword;dword;ptr*);" & _
        "GetDevice hresult(wstr;ptr*);" & _
        "RegisterEndpointNotificationCallback hresult(ptr);" & _
        "UnregisterEndpointNotificationCallback hresult(ptr);"
Global $o_MMDeviceEnumerator = ObjCreateInterface($sCLSID_MMDeviceEnumerator, $sIID_IMMDeviceEnumerator, $tagIMMDeviceEnumerator)


$o_MMDeviceEnumerator.RegisterEndpointNotificationCallback($p_IMMNotificationClient)
OnAutoItExitRegister("_UnregisterEndpointNotificationCallback")
Func _UnregisterEndpointNotificationCallback()
    $o_MMDeviceEnumerator.UnregisterEndpointNotificationCallback($p_IMMNotificationClient)
EndFunc   ;==>_UnregisterEndpointNotificationCallback


; ===================================================================================
; Main Loop
#include <Misc.au3>
While Sleep(10)
    If _IsPressed("1B") Then ExitLoop ; ESC to exit
WEnd

 

Share this post


Link to post
Share on other sites

Dear brother
to be  everything is clear for me
please provide this service to me
I want when I change the default audio output the script execute these commands
####
    _BASS_Free()
_BASS_Startup(@scriptDir & "\dll\bass.dll")
If @error = -1 Then
    MsgBox (0, "", "DLL Does not exist?  Please check file exists.")
    Exit
EndIf
_BASS_Init(0, -1, 44100, 0, "")
If @error Then
    MsgBox(0, "Error", "Could not initialize audio")
    Exit
EndIf
$MusicHandle = _BASS_StreamCreateFile(False, $file, 0, 0, 0)
_BASS_ChannelSetDevice($MusicHandle, 1)
_BASS_ChannelSetvolume($MusicHandle, $volume)

autoefect()
_BASS_ChannelPlay($MusicHandle, 1)
_BASS_ChannelSetPosition($MusicHandle, $restartPlaying, $BASS_POS_BYTE)
###
I'm sorry if I upset you
greetings

 

Share this post


Link to post
Share on other sites
; _IMMNotificationClient

; By KaFu, based on this example by trancexx
; http://www.autoitscript.com/forum/topic/151474-looking-to-capture-immnotificationclientondevicestatechanged-events/#entry1084193

Global $iAudioSwitched = 0

Global $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc")
Func _ErrFunc($oError)
    ConsoleWrite("COM Error, ScriptLine(" & $oError.scriptline & ") : Number 0x" & Hex($oError.number, 8) & " - " & $oError.windescription & @CRLF)
EndFunc   ;==>_ErrFunc


; Global Const $sIID_IMMNotificationClient = "{7991EEC9-7E89-4D85-8390-6C703CEC60C0}"
Global Const $tagIMMNotificationClient = "OnDeviceStateChanged hresult(wstr;dword);" & _
        "OnDeviceAdded hresult(wstr);" & _
        "OnDeviceRemoved hresult(wstr);" & _
        "OnDefaultDeviceChanged hresult(dword;dword;wstr);" & _
        "OnPropertyValueChanged hresult(wstr;int64);" ; last param type is improvisation because AutoIt lacks proper type

Func _IMMNotificationClient_OnDeviceStateChanged($hresult, $wstr, $dword)
    #forceref $hresult
    ConsoleWrite("_IMMNotificationClient_OnDeviceStateChanged" & @TAB & $wstr & @TAB & $dword & @CRLF)
    Return 0 ; S_OK
EndFunc   ;==>_IMMNotificationClient_OnDeviceStateChanged

Func _IMMNotificationClient_OnDeviceAdded($hresult, $wstr)
    #forceref $hresult
    ConsoleWrite("_IMMNotificationClient_OnDeviceAdded" & @TAB & $wstr & @CRLF)
    Return 0 ; S_OK
EndFunc   ;==>_IMMNotificationClient_OnDeviceAdded

Func _IMMNotificationClient_OnDeviceRemoved($hresult, $wstr)
    #forceref $hresult
    ConsoleWrite("_IMMNotificationClient_OnDeviceRemoved" & @TAB & $wstr & @CRLF)
    Return 0 ; S_OK
EndFunc   ;==>_IMMNotificationClient_OnDeviceRemoved

Func _IMMNotificationClient_OnDefaultDeviceChanged($hresult, $dword1, $dword2, $wstr)
    #forceref $hresult
    ConsoleWrite("_IMMNotificationClient_OnDefaultDeviceChanged" & @TAB & $dword1 & @TAB & $dword2 & @TAB & $wstr & @CRLF)
    $iAudioSwitched = TimerInit()
    Return 0 ; S_OK
EndFunc   ;==>_IMMNotificationClient_OnDefaultDeviceChanged

Func _IMMNotificationClient_OnPropertyValueChanged($hresult, $wstr, $int64)
    #forceref $hresult
    ConsoleWrite("_IMMNotificationClient_OnPropertyValueChanged" & @TAB & $wstr & @TAB & $int64 & @CRLF)
    Return 0 ; S_OK
EndFunc   ;==>_IMMNotificationClient_OnPropertyValueChanged

#cs
    Global Const $sIID_IUnknown = "{00000000-0000-0000-C000-000000000046}"
    Global Const $tagMyInterface = "FirstMethod hresult(wstr);" & _
    "SecondMethod hresult(int;wstr);"
#ce

Global $t_IMMNotificationClient
Global $o_IMMNotificationClient = ObjectFromDtag("_IMMNotificationClient_", $tagIMMNotificationClient, $t_IMMNotificationClient)
; Global $p_IMMNotificationClient = ptr($o_IMMNotificationClient())
Global $p_IMMNotificationClient = $o_IMMNotificationClient()

#cs
    ; Is object get?
    ConsoleWrite("!!! IsObj($oMyObject) = " & IsObj($o_IMMNotificationClient) & @CRLF)
    $o_IMMNotificationClient.OnDeviceRemoved("Test")
    ; Get object pointer:
    ConsoleWrite("+>>> Object pointer = " & $o_IMMNotificationClient() & @CRLF)
#ce

Func ObjectFromDtag($sFunctionPrefix, $tagInterface, ByRef $tInterface)
    Local Const $tagIUnknown = "QueryInterface hresult(ptr;ptr*);" & _
            "AddRef dword();" & _
            "Release dword();"
    ; Adding IUnknown methods
    $tagInterface = $tagIUnknown & $tagInterface
    Local Const $PTR_SIZE = DllStructGetSize(DllStructCreate("ptr"))
    ; Below line really simple even though it looks super complex. It's just written weird to fit one line, not to steal your eyes
    Local $aMethods = StringSplit(StringReplace(StringReplace(StringReplace(StringReplace(StringTrimRight(StringReplace(StringRegExpReplace($tagInterface, "\h*(\w+)\h*(\w+\*?)\h*(\((.*?)\))\h*(;|;*\z)", "$1\|$2;$4" & @LF), ";" & @LF, @LF), 1), "object", "idispatch"), "variant*", "ptr"), "hresult", "long"), "bstr", "ptr"), @LF, 3)
    Local $iUbound = UBound($aMethods)
    Local $sMethod, $aSplit, $sNamePart, $aTagPart, $sTagPart, $sRet, $sParams
    ; Allocation. Read http://msdn.microsoft.com/en-us/library/ms810466.aspx to see why like this (object + methods):
    $tInterface = DllStructCreate("ptr[" & $iUbound + 1 & "]")
    If @error Then Return SetError(1, 0, 0)
    For $i = 0 To $iUbound - 1
        $aSplit = StringSplit($aMethods[$i], "|", 2)
        If UBound($aSplit) <> 2 Then ReDim $aSplit[2]
        $sNamePart = $aSplit[0]
        $sTagPart = $aSplit[1]
        $sMethod = $sFunctionPrefix & $sNamePart
        $aTagPart = StringSplit($sTagPart, ";", 2)
        $sRet = $aTagPart[0]
        $sParams = StringReplace($sTagPart, $sRet, "", 1)
        $sParams = "ptr" & $sParams
        DllStructSetData($tInterface, 1, DllCallbackGetPtr(DllCallbackRegister($sMethod, $sRet, $sParams)), $i + 2) ; Freeing is left to AutoIt.
    Next
    DllStructSetData($tInterface, 1, DllStructGetPtr($tInterface) + $PTR_SIZE) ; Interface method pointers are actually pointer size away
    Return ObjCreateInterface(DllStructGetPtr($tInterface), "", $tagInterface, False) ; and first pointer is object pointer that's wrapped
EndFunc   ;==>ObjectFromDtag



Global Const $sCLSID_MMDeviceEnumerator = "{BCDE0395-E52F-467C-8E3D-C4579291692E}"
Global Const $sIID_IMMDeviceEnumerator = "{A95664D2-9614-4F35-A746-DE8DB63617E6}"

Global Const $tagIMMDeviceEnumerator = "EnumAudioEndpoints hresult(dword;dword;ptr*);" & _
        "GetDefaultAudioEndpoint hresult(dword;dword;ptr*);" & _
        "GetDevice hresult(wstr;ptr*);" & _
        "RegisterEndpointNotificationCallback hresult(ptr);" & _
        "UnregisterEndpointNotificationCallback hresult(ptr);"
Global $o_MMDeviceEnumerator = ObjCreateInterface($sCLSID_MMDeviceEnumerator, $sIID_IMMDeviceEnumerator, $tagIMMDeviceEnumerator)


$o_MMDeviceEnumerator.RegisterEndpointNotificationCallback($p_IMMNotificationClient)
OnAutoItExitRegister("_UnregisterEndpointNotificationCallback")
Func _UnregisterEndpointNotificationCallback()
    $o_MMDeviceEnumerator.UnregisterEndpointNotificationCallback($p_IMMNotificationClient)
EndFunc   ;==>_UnregisterEndpointNotificationCallback


; ===================================================================================
; Main Loop
#include <Misc.au3>
While Sleep(10)

    ; If _IsPressed("1B") Then ExitLoop ; ESC to exit

    if $iAudioSwitched and TimerDiff($iAudioSwitched) > 250 then
        ConsoleWrite("Audio switched" & @crlf)
        
            _BASS_Free()
            _BASS_Startup(@scriptDir & "\dll\bass.dll")
            If @error = -1 Then
                MsgBox (0, "", "DLL Does not exist?  Please check file exists.")
                Exit
            EndIf
            _BASS_Init(0, -1, 44100, 0, "")
            If @error Then
                MsgBox(0, "Error", "Could not initialize audio")
                Exit
            EndIf
            $MusicHandle = _BASS_StreamCreateFile(False, $file, 0, 0, 0)
            _BASS_ChannelSetDevice($MusicHandle, 1)
            _BASS_ChannelSetvolume($MusicHandle, $volume)

            autoefect()
            _BASS_ChannelPlay($MusicHandle, 1)
            _BASS_ChannelSetPosition($MusicHandle, $restartPlaying, $BASS_POS_BYTE)
        
        $iAudioSwitched = 0
    endif

WEnd

 

Share this post


Link to post
Share on other sites

Hello
First, I want to apologize to you on this issue
I urgently need to convert this code into an include file and simplify it

 

; _IMMNotificationClient

; By KaFu, based on this example by trancexx
; http://www.autoitscript.com/forum/topic/151474-looking-to-capture-immnotificationclientondevicestatechanged-events/#entry1084193

Global $iAudioSwitched = 0

Global $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc")
Func _ErrFunc($oError)
ConsoleWrite("COM Error, ScriptLine(" & $oError.scriptline & ") : Number 0x" & Hex($oError.number, 8) & " - " & $oError.windescription & @CRLF)
EndFunc


; Global Const $sIID_IMMNotificationClient = "{7991EEC9-7E89-4D85-8390-6C703CEC60C0}"
Global Const $tagIMMNotificationClient = "OnDeviceStateChanged hresult(wstr;dword);" & _
"OnDeviceAdded hresult(wstr);" & _
"OnDeviceRemoved hresult(wstr);" & _
"OnDefaultDeviceChanged hresult(dword;dword;wstr);" & _
"OnPropertyValueChanged hresult(wstr;int64);" ; last param type is improvisation because AutoIt lacks proper type

Func _IMMNotificationClient_OnDeviceStateChanged($hresult, $wstr, $dword)
#forceref $hresult

Return 0 ; S_OK
EndFunc

Func _IMMNotificationClient_OnDeviceAdded($hresult, $wstr)
#forceref $hresult
Return 0 ; S_OK
EndFunc

Func _IMMNotificationClient_OnDeviceRemoved($hresult, $wstr)
#forceref $hresult
Return 0 ; S_OK
EndFunc

Func _IMMNotificationClient_OnDefaultDeviceChanged($hresult, $dword1, $dword2, $wstr)
#forceref $hresult
$iAudioSwitched = TimerInit()
Return 0 ; S_OK
EndFunc

Func _IMMNotificationClient_OnPropertyValueChanged($hresult, $wstr, $int64)
#forceref $hresult

Return 0 ; S_OK
EndFunc

#cs
Global Const $sIID_IUnknown = "{00000000-0000-0000-C000-000000000046}"
Global Const $tagMyInterface = "FirstMethod hresult(wstr);" & _
"SecondMethod hresult(int;wstr);"
#ce

Global $t_IMMNotificationClient
Global $o_IMMNotificationClient = ObjectFromDtag("_IMMNotificationClient_", $tagIMMNotificationClient, $t_IMMNotificationClient)
; Global $p_IMMNotificationClient = ptr($o_IMMNotificationClient())
Global $p_IMMNotificationClient = $o_IMMNotificationClient()

#cs
; Is object get?
ConsoleWrite("!!! IsObj($oMyObject) = " & IsObj($o_IMMNotificationClient) & @CRLF)
$o_IMMNotificationClient.OnDeviceRemoved("Test")
; Get object pointer:
ConsoleWrite("+>>> Object pointer = " & $o_IMMNotificationClient() & @CRLF)
#ce

Func ObjectFromDtag($sFunctionPrefix, $tagInterface, ByRef $tInterface)
Local Const $tagIUnknown = "QueryInterface hresult(ptr;ptr*);" & _
"AddRef dword();" & _
"Release dword();"
; Adding IUnknown methods
$tagInterface = $tagIUnknown & $tagInterface
Local Const $PTR_SIZE = DllStructGetSize(DllStructCreate("ptr"))
; Below line really simple even though it looks super complex. It's just written weird to fit one line, not to steal your eyes
Local $aMethods = StringSplit(StringReplace(StringReplace(StringReplace(StringReplace(StringTrimRight(StringReplace(StringRegExpReplace($tagInterface,"\h*(\w+)\h*(\w+\*?)\h*(\((.*?)\))\h*(;|;*\z)", "$1\|$2;$4" & @LF), ";" & @LF, @LF), 1), "object", "idispatch"), "variant*", "ptr"), "hresult", "long"),"bstr", "ptr"), @LF, 3)
Local $iUbound = UBound($aMethods)
Local $sMethod, $aSplit, $sNamePart, $aTagPart, $sTagPart, $sRet, $sParams
; Allocation. Read http://msdn.microsoft.com/en-us/library/ms810466.aspx to see why like this (object + methods):
$tInterface = DllStructCreate("ptr[" & $iUbound + 1 & "]")
If @error Then Return SetError(1, 0, 0)
For $i = 0 To $iUbound - 1
$aSplit = StringSplit($aMethods[$i], "|", 2)
If UBound($aSplit) <> 2 Then ReDim $aSplit[2]
$sNamePart = $aSplit[0]
$sTagPart = $aSplit[1]
$sMethod = $sFunctionPrefix & $sNamePart
$aTagPart = StringSplit($sTagPart, ";", 2)
$sRet = $aTagPart[0]
$sParams = StringReplace($sTagPart, $sRet, "", 1)
$sParams = "ptr" & $sParams
DllStructSetData($tInterface, 1, DllCallbackGetPtr(DllCallbackRegister($sMethod, $sRet, $sParams)), $i + 2) ; Freeing is left to AutoIt.
Next
DllStructSetData($tInterface, 1, DllStructGetPtr($tInterface) + $PTR_SIZE) ; Interface method pointers are actually pointer size away
Return ObjCreateInterface(DllStructGetPtr($tInterface), "", $tagInterface, False) ; and first pointer is object pointer that's wrapped
EndFunc

 

Global Const $sCLSID_MMDeviceEnumerator = "{BCDE0395-E52F-467C-8E3D-C4579291692E}"
Global Const $sIID_IMMDeviceEnumerator = "{A95664D2-9614-4F35-A746-DE8DB63617E6}"

Global Const $tagIMMDeviceEnumerator = "EnumAudioEndpoints hresult(dword;dword;ptr*);" & _
"GetDefaultAudioEndpoint hresult(dword;dword;ptr*);" & _
"GetDevice hresult(wstr;ptr*);" & _
"RegisterEndpointNotificationCallback hresult(ptr);" & _
"UnregisterEndpointNotificationCallback hresult(ptr);"
Global $o_MMDeviceEnumerator = ObjCreateInterface($sCLSID_MMDeviceEnumerator, $sIID_IMMDeviceEnumerator, $tagIMMDeviceEnumerator)


$o_MMDeviceEnumerator.RegisterEndpointNotificationCallback($p_IMMNotificationClient)
OnAutoItExitRegister("_UnregisterEndpointNotificationCallback")
Func _UnregisterEndpointNotificationCallback()
$o_MMDeviceEnumerator.UnregisterEndpointNotificationCallback($p_IMMNotificationClient)
EndFunc


; ===================================================================================
; Main Loop


FUNC outputChanged()
if $iAudioSwitched and TimerDiff($iAudioSwitched) > 250 then
$iAudioSwitched = 0
RETURN 1
ELSE
$iAudioSwitched = 0
RETURN 0
endif

EndFunc

Share this post


Link to post
Share on other sites

Please, dear, try to help me to integrate this example. In a audio player program
When i try to make it as a include file as this way, it  obstruct several tasks in the program.
And I couldn't figure out why.
This is the include file
Please help me

 

audioOutputIsChanged.au3

Share this post


Link to post
Share on other sites
1 hour ago, nacerbaaziz said:

it  obstruct several tasks in the program.

What do you mean by this? what's not working, and what, if any, errors are you seeing?


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

There's a error message that some of the variables in the program is Not Declarated

وهذه المتغيرات ليس لها علاقة بهذا الرمز.
حيث
انها مسؤوله عن أمور أخرى في البرنامج
please help me

Share this post


Link to post
Share on other sites

Declare them then. I'm not getting that from what you posted by the way, so it is somewhere else that you're getting that error. Probably in you main script or one of the other includes you might have in it.

There's no way to troubleshoot this without know what variables aren't declared or where they're used in the script.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By ripdad
      This is an example script of how to load and use a VST using BASS in AutoIt.
      It is NOT immediately Plug and Play. You will need to download 2 VST's to run it.
      They are free for personal use.
      All information is in the header of the script.

      Download:
      BASS VST HOST v0.4.zip
       
    • By CYCho
      This file includes all the source codes and a compiled .exe version of zPlayer, which is a stand-alone, simple, intuitive and easy-to-use, yet fully functional audio player.  I made this to suit my purpose and you can tweak it to your taste as the source code is only about 1000 lines which are very much readable.  This player has the following functions:
      - Play back all formats of audio files which can be palyed back by the Windows Media Player in your computer
      - Graphical player similar to embedded Windows Media Player
      - Forward, backward, pause, repeat, shuffle funtions
      - Increase/decrease/mute sound volume
      - Change folders and create playlist for all audio files in that folder and its subfolders, and support for manually-made playlists
      - Save play-back environment when terminating and resume that environment when restarting
      - With one click, you can see DuckDuckGo search results for the file being played back
      - With a double-click, you can play back an item in the playlist
      - Search strings in the playlist
      - Option to see long file names including folder names
      - Resize the playlist window, and restore it to its default position
      - Very small footprint: very low CPU and memory usage, with only about 1MB when compiled
      - You can even hide all the windows and manipulate the player with hotkeys only
      Note: zPlayer is the name I used when I introduced the early version of this palyer in my blog back in early 2009 and, therefore, has nothing to do with the mobile media player of the same name which started marketing in 2015.
    • By PeterVerbeek
      In this post I take the opportunity to show the awesome capabilities of AutoIt and its libraries. My open source project Peace is a long running AutoIt based app located on SourceForge. It provides users with a system-wide equalizer and effects machine. It's an interface using the power of Equalizer APO, an audio processing object software. Peace has been download over 1,100,000 times by various kind of users. Amongst others it gives them possibilities like these:
      Hearing impaired - Amplify the gain of frequencies which are impaired. Home Theatre - Create Equalizer presets for watching movies and listening to music. Music lovers & audiophiles - Create presets for listening to music on their high quality speakers and headphones. Gamers - Enhance frequencies to get an edge over other gamers. Headphones - Improve the sound quality of cheap headphones and get the max out of expensive ones. Bass lovers - Boost low frequencies for extra bass. Voice - Make a microphone sound better and improve the voice, for instance for YouTube usage. Low audio - Boost low audio of an input source to a comfortable level. This list covers the main needs of the Peace user. Many people have contacted me over the years asking for new features and telling me how they use Peace for their (sometimes specific) needs.  I was able to use AutoIt and its libraries for all of their needs. So what are the main features of Peace?
      Equalize your computer audio by using up to 31 sliders. Support of equalizing 9 speakers : left/right, center, subwoofer, left/right rear, left/right side. Per slider a filter can be chosen such as peak, low/high pass, shelving. The graph windows shows your equalization so you see exactly what you're doing. Apply an effect such as crossfeed simple/Jan Meier/Chu Moy, stereo balance, bass/treble, upmix/downmix, channel routing. Save presets (called configurations) and activate by mouse click, hotkey, desktop shortcut or Peace system tray. Select a target device to equalize, microphone as input can also be equalized. Automate: you can let Peace automatically activate presets on a switch to another device and another process. Peace is available in these languages: English, Czech, Deutsch, Français, Italiano, Nederlands, Pусский, Українська So who am I? I'm a Dutch programmer who happens the stumble upon AutoIt 5 years ago and created a small Equalizer interface app of less than 400 program lines with it. Nowadays Peace has grown to more than 17,000 lines as many features were added. Although Peace is open source, the program code isn't of the best possible quality. The reason being that I didn't expect it to become so popular. It caught me by supprise. I've created a Library of functions called Pal (link to forum post) which quality is up to the AutoIt community standard as counterpart to the Peace program code.
      I want to state here that AutoIt is a mature program language as Peace obviously shows. I wish it to be used more extensively for professional or semi-professional apps. In my view AutoIt deserves a place amongst the major programming languages for Windows computers.
      Regards,
      Peter Verbeek







    • By ripdad
      I ran across a topic while researching the BASS UDF...
      https://www.autoitscript.com/forum/topic/155845-carpenter-needs-help-performing-serious-surgery-on-audiometer2/ and then remembered another topic...
      https://www.autoitscript.com/forum/topic/121624-sound-level-sampling/ which got me to thinking as to how I could get the first topic to go LIVE without the need of loading an mp3.
      This will accept any LIVE AUDIO INPUT.
      Be sure to read this post if you have trouble with it...
      https://www.autoitscript.com/forum/topic/121624-sound-level-sampling/?do=findComment&comment=1400178 Also, read the comments I made in the script, so you will know how it will react to LIVE INPUT streams.

      Live FFT Visual Spectrum.zip
       

      LIVE Multiband FFT Visual Spectrum.au3
       
    • By nacerbaaziz
      hello sirs, i've created a tool to the blind users, this tool helps the blind to listen to a audio effect when moving between the GUIs controls on they computers
      where this tool can get the class for the current focus control and play a sound from a folder
      i've added all the knowne classes, but i found some problems i hope any one can help me.
      this is the code that i created

      #include <WinAPISys.au3> Global $h_CurrentHWNDFocus = "", $h_CurrentControlHWNDFocus = "" AdlibRegister("WindowAudioFocus", 50) Func WindowAudioFocus()     Local $h_NewHWNDFocus = WinGetHandle("[active]", "")     Local $h_NewControlHWNDFocus = ControlGetFocus($h_NewHWNDFocus, "")     If ($h_NewHWNDFocus = $h_CurrentHWNDFocus) And ($h_NewControlHWNDFocus = $h_CurrentControlHWNDFocus) Then Return 0     AdlibUnRegister("WindowAudioFocus")     If Not ($h_NewHWNDFocus = $h_CurrentHWNDFocus) Then         SoundPlay(@ScriptDir & "\focus_Audio\WindowChanged.wav")     Else         Switch _WinAPI_GetClassName(ControlGetHandle($h_NewHWNDFocus, "", $h_NewControlHWNDFocus))             Case "Button", "Start", "TrayButton", "TrayShowDesktopButtonWClass", "sbutton", "CirrussButton", "ODbcButton", "ThunderRTCommandButton", "ThunderSSOption", "ThunderSSCommand", "ThunderCommandButton", "ThunderRT6CommandButton", "ThunderRT5CommandButton", "TButton", "TBitBtn", "TAdvGlowButton", "ButtonWndClass", "afx:0:376:baa946", "_AOL_Button"                 If _IsCheckBox(ControlGetHandle($h_NewHWNDFocus, "", $h_NewControlHWNDFocus)) Then                     SoundPlay(@ScriptDir & "\focus_Audio\checkBox.wav")                 ElseIf _IsRadio(ControlGetHandle($h_NewHWNDFocus, "", $h_NewControlHWNDFocus)) Then                     SoundPlay(@ScriptDir & "\focus_Audio\radio.wav")                 Else                     SoundPlay(@ScriptDir & "\focus_Audio\button.wav")                 EndIf             Case "ComboBox", "ComboBoxEx32", "MSOBALLOONREComboBox20W", "REComboBox20W", "ThunderComboBox", "ThunderDriveListBox", "ThunderRT6ComboBox", "TORComboEdit", "TCombobox", "TComboBoxEx", "TORComboBox", "TColorBox", "TNFComboBox", "Internet Explorer_TridentCmbobx", "ComboWndClass", "_AOL_ComboBox", "ThunderRT5ComboBox", "ComboLBox"                 SoundPlay(@ScriptDir & "\focus_Audio\list.wav")             Case "Edit", "SearchBox", "TChatRichEdit", "_WwN", "_WwO", "RichEdit20A", "RichEdit20WPT", "RICHEDIT60W", "OKttbx", "RichEditA", "ThunderTextBox", "ThunderRT6TextBox", "ThunderRT5TextBox", "TEdit", "TRichEdit", "TRichEditViewer", "TMemo", "TInplaceEditList", "TLabeledEdit", "TMaskEdit", "TDateTimePicker", "TRichEdit", "TCaptionMemo", "TAddictRichEdit", "TCaptionEdit", "RichTextWndClass", "TextWndClass", "PasswordWndClass", "TextAreaWndClass", "MSWorksDoc", "_AOL_Edit", "SysDateTimePick32"                 SoundPlay(@ScriptDir & "\focus_Audio\edit.wav")             Case "ListBox", "ComboLBox", "REListBox20W", "SUPERGRID", "OUTEXVLB", "WMSUIVLB", "SchdmapiVLB", "VLBClass", "ThunderDirListBox", "ThunderFileListBox", "ThunderListBox", "ThunderRT6ListBox", "ThunderRT5ListBox", "TListbox", "TValueListEditor", "TORCalendar", "TColorListBox", "TCheckListBox", "Internet Explorer_TridentLstBox", "ListBoxWndClass", "ListWndClass", "hh_kwd_vlist", "afx:8:376:0:946", "_AOL_ListBox", "_AOL_Tree", ""                 SoundPlay(@ScriptDir & "\focus_Audio\List.wav")             Case "SysListView32", "OpenListView", "wuDuiListView", "ListView20WndClass", "TcxGridSite", "TListView", "TSystemListView", "ListViewWndClass", ""                 SoundPlay(@ScriptDir & "\focus_Audio\ListView.wav")             Case "SysTreeView32", "SearchTreeList", "FeatureTree", "TreeView20WndClass", "TSystemTreeView", "TTreeView", ""                 SoundPlay(@ScriptDir & "\focus_Audio\TreeView.wav")             Case Else                 SoundPlay(@ScriptDir & "\focus_Audio\focus.wav")         EndSwitch     EndIf     $h_CurrentHWNDFocus = $h_NewHWNDFocus     $h_CurrentControlHWNDFocus = $h_NewControlHWNDFocus     AdlibRegister("WindowAudioFocus", 50)     Return 1 EndFunc   ;==>WindowAudioFocus Func _IsCheckBox($ctrl_hwnd)     $Style = _WinAPI_GetWindowLong($ctrl_hwnd, $GWL_STYLE)     Return BitAND($Style, $BS_CHECKBOX) = $BS_CHECKBOX EndFunc   ;==>_IsCheckBox Func _IsRadio($ctrl_hwnd)     $Style = _WinAPI_GetWindowLong($ctrl_hwnd, $GWL_STYLE)     Return BitAND($Style, $BS_AUTORADIOBUTTON) = $BS_AUTORADIOBUTTON EndFunc   ;==>_IsRadio
      what i need from you is :
      play a sound when a menu item focus, that sound named menu.wav
      play a sound named items.wav when the users move on list box items or list view or treeview items or a combobox items
      please if can any one help me i'll very happy
      thanks on advance
×
×
  • Create New...