Jump to content
nacerbaaziz

Detect if the audio output is changed

Recommended Posts

nacerbaaziz

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
Confuzzled

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
Danyfirex

Share this post


Link to post
Share on other sites
nacerbaaziz

Sorry I want an example using autoit

Share this post


Link to post
Share on other sites
KaFu
; _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
nacerbaaziz

Sorry dear
i not understand very well
please I want more clarification

Share this post


Link to post
Share on other sites
KaFu
nacerbaaziz

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
KaFu
; _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
nacerbaaziz

Hello again
can you correct the errors in this file after you adjust it according to what suits me. please

When I use it I am having many errors
I want it as an include file
to use it in my program
Please help me dear!
Greetings to all

audioOutputIsChanged.au3

Share this post


Link to post
Share on other sites
nacerbaaziz

Hello , good morning


Is there anyone who can help me to correct the previous include file?
I could not correct it with  myself

thank you.

Share this post


Link to post
Share on other sites
nacerbaaziz

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
MattHiggs
1 hour ago, nacerbaaziz said:

nnm

Edited by MattHiggs

Share this post


Link to post
Share on other sites
nacerbaaziz
19 minutes ago, MattHiggs said:

 

Sorry but I did not understand what you said

Share this post


Link to post
Share on other sites
nacerbaaziz

Is there any suggestion about how to  do this file as a include file please?

I mean the file in comment above

Share this post


Link to post
Share on other sites
nacerbaaziz

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
BrewManNH
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
nacerbaaziz

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
BrewManNH

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
nacerbaaziz

But the problem is if I don't include this file, everything's fine.

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

  • Similar Content

    • TheSaint
      By TheSaint
      This is my latest project, which I have been working on for a few days now, so this is kind of hot off the press. However, in reality, I have been working on some element of this for years. Some of you may remember a huge project of mine (Audio DVD Producer + Chat Blog Screenshots) that I worked on a good while back? Well, this one is very much related, and very much simpler in scope. That other project by the way, has been basically stalled for a good length of time now. Not because I never finished it, but because the end result was not as great as I hoped. I may share the files for it one day. I may even start working on it again one day, though this latest project kind of makes much of it redundant for my aims.
      Anyway, this project. I have a good bunch of DTS-CDs, from same or other sources (i.e. DVD). You can read more about what a DTS-CD is here, but the short of it, is that you cannot play them on a normal CD player, as you will just get noise. Many if not most DVD or Blu-ray players can play the embedded DTS data in the otherwise empty CD tracks. Further to that, a DTS-CD is essentially a compressed PCM or WAV file for all intents and purposes ... to keep things simple. So a 6 Channel (5.1) track takes up roughly the same amount of bytes as a normal stereo CD track ... so 6 channels for the price of 2.
      Up until recently, the best device for me to play the DTS-CDs on, as CDs, is my PS3. It plays them faithfully (reader issues aside) and has nice visuals. It is also my most convenient DVD/Blu-ray player, so a heap of hassle to play on one of my regular players, and not much success with the Xbox 360 ... at least with burnt backup copies.
      DTS-CDs are also kind of old school, and been superseded by the more superior lossless DVD Audio, Super CD and now Blu-ray Audio discs. That kind of makes them rare now and essentially irreplaceable, so being a wise man, I store them safely and only play backup discs.
      Playing discs though is kind of limited, and to be honest a pain, as my PS3 spits the dummy on some days, with the reader not being what its should be ... or perhaps poorly calibrated. So for a long time now, I have been wanting to use the backup files instead. Unfortunately, while I can play them fine on my PC (foobar2000 + DTS plugin), that is not where I want to listen to them. Until recently, neither my NeoTV 550 hardware player or my Laser one, have been very good at playing the files, and the PS3 even worse with its lack of file support. Back when I first investigated all this, and tried a bunch of things, and didn't yet have the Laser (4k Android) player, I did attempt to go the FLAC route. However, I was left unsatisfied, as my NeoTV did not support CUE files and M3U playlist files are a bit of a hassle ... and no help, when I have a single album file with cue index points for each track ... which many of my DTS-CD rips were ... especially for albums that have one track running into the next ... live albums too. The other issues for me with FLAC, were the artwork (album cover) and TAGS (details for each track - Title, Artist, Album, Year, etc), which I could not get to work.
      So, moving forward to recently. I played a DTS-CD on the PS3 the other day, and if there is one things I hate, it is a playing issue when I am in the midst of enjoying a nice piece of music. The PS3 is not very forgiving and just aborts play. I am not very forgiving of the PS3, so decided to investigate FLACs again. Now perhaps something has changed, since I last tried ... or I just wasn't on the ball. Anyway, to cut a long story a bit shorter, I loaded a DTS WAV file in foobar2000, and ripped it to a FLAC file. I then tried that file on my NeoTV 550 hardware player, and it played fine ... and some tags were visible, which surprised me. So I thought it was worth looking into further. I also tried the file on my Laser hardware player, with the Kodi (XBMC) Android app, but alas, while the Tags and Artwork worked well, all I got was noise ... and same for every other app I tried.
      Now don't ask me why I thought to try FLAC on its own, using the FLAC Frontend program initially, but I did ... and it recognized the tracks as 5.1. With foobar2000, I'd selected the decoder for DTS files when converting to FLAC, as I thought it was required. I hadn't at that stage used flac.exe by itself, but I decided to investigate the TAG command-line options and also noticed you could embed a picture, which I was keen as mustard to try. So I set up a BAT file and gave it a whirl.
      Now the results on my NeoTV 550 hardware player, were brilliant - Sound, Tags and Artwork were as I wanted. I decided to update Kodi at that point. Then, I tried my Laser hardware player again, but still no joy. I then did some online research and read about how to get it all working. Alas, I had mixed results. The foobar2000 ripped file worked, but the one I did with the BAT file did not. Not being keen to rip everything via foobar2000 menus, and wanting to code a quicker batch solution myself, I first attempted to see what command-line options I could use for foobar. That was a dismal failure, so I then revisited some of the programs I had used way back when with DTS WAV based files, and eventually discovered that 'valdec.exe' from the AC3Filter tools collection, gave the compatibility I needed. So I put my WAV or DTS files through that program first, then converted them to FLAC.
      Now the files played with DTS surround sound, on both my hardware players. They also play gapless, so I split album length files into separate track files, which avoids the CUE and M3U issues. That said, a joined M3U file for something like a (separate folders) double album, plays great with Kodi.
      So of course, I just had to whip up a program ... with drag and drop of course.
      And that program has steadily been growing & changing, and is where I want it now, at v1.5.
      Screenshots further below.
      REQUIRED COMPONENTS
      Most programs (if not all) can be obtained from VideoHelp, but here are some alternative sites to source them. The 'flac.exe' program is definitely required, and 'valdec.exe' if you want maximum compatibility support for a wider range of players.
      [flac.exe]
      https://xiph.org/flac/
      https://xiph.org/flac/download.html
      https://ftp.osuosl.org/pub/xiph/releases/flac/
      https://ftp.osuosl.org/pub/xiph/releases/flac/flac-1.3.1-win.zip
      [valdec.exe] [found in the AC3Filter tools collection]
      http://www.ac3filter.net/wiki/AC3Filter_tools (Info only, downloads no longer work)
      https://web.archive.org/web/*/http://www.ac3filter.net/wiki/AC3Filter_tools
      https://web.archive.org/web/20130623004920/http://www.ac3filter.net:80/wiki/Download_AC3Filter_tools
      If The Wayback Machine options fail, then go to VideoHelp (maybe go there anyway).
      https://www.videohelp.com/software/AC3-Filter/old-versions
      NOTE - The AC3Filter site has loads of information, which could help you enable other players aside from those below.
      RECOMMENDED PLAYERS
      PC = foobar2000 + DTS plugin component.
      Android Device = Kodi (XBMC) app with DTS etc enabled with passthrough.
      NOTE - foobar2000 with plugin, will play even those not processed with 'valdec.exe'. My 'NeoTV 550' hardware player does the same. My 'Laser' (Android device) with Kodi just emits noise with the FLAC files, if not processed with 'valdec.exe'.
      RECOMMENDED DTS-CD RIPPERS
      http://www.imgburn.com/
      http://www.exactaudiocopy.de/
      OTHER LINKS
      This one of mine tells you a lot more about DTS-CDs, including ripping or burning.
      https://forum.doom9.org/showthread.php?t=172484
      SCREENSHOTS
         

      P.S. I made a brilliant discovery today. Whereas in the past, with PS3 etc, I could not listen to my DTS-CDs via my Surround Sound Headphones, I now can with these files. So it is well worth playing those CDs as files, just for that benefit alone. Overall though, I have future proofed my collection.
    • nacerbaaziz
      By nacerbaaziz
      hello
      Hi dear, I have a question please
      I designed a function to read the content of the playlist
      I succeeded in that
      I have a problem
      For VLC player playlists
      If the path of the files in Arabic language the path is be as follows
      %D8%A3%D8%B0%D9%83%D8%A7%D8%B1%20%D9%88%D8%A3%D8%AF%D8%B9%D9%8A%D8%A9/%D8%A3%D8%B0%D9%83%D8%A7%D8%B1%20%D9%85%D9%86%D9%88%D8%B9%D8%A9/%D8%A3%D8%B0%D9%83%D8%A7%D8%B1%2003.mp3
      I did not know how to decrypt this text to be readable
      This is the function that i used

      func M3UImport($M3UFile) dim $AM3UItems local $fileOpen = FileOpen($path, bitOr($FO_OVERWRITE,$FO_CREATEPATH,$FO_ANSI)) _FileReadToArray ($fileOpen, $AM3UItems) if @error then return setError(1) local $M3UPath for $i = 1 to $AM3UItems[0] $AM3UItems[$i] = stringReplace($AM3UItems[$i], "file:///", "") $AM3UItems[$i] = stringReplace($AM3UItems[$i], "/", "\") $AM3UItems[$i] = stringReplace($AM3UItems[$i], "%20", " ") $M3UPath = _fileGetDirPath($AM3UItems[$i]) if $M3UPath = "" then $M3UPath = @WorkingDir if not StringTrimRight($M3UPath, 1) = "\" then $M3UPath &= "\" $AM3UItems[$i] = $M3UPath & $AM3UItems[$i] endIf local $ext = _GetFileExt($AM3UItems[$i]) if fileExists($AM3UItems[$i]) and not (StringInStr($FilesExt, $ext) = 0) then $aListItems[0] += 1 GUICtrlCreateListViewItem(_GetFileName($AM3UItems[$i]) & Opt("GUIDataSeparatorChar") & " : " & Opt("GUIDataSeparatorChar") & $AM3UItems[$i], $list) endIf next return "" endFunc

      I ask for your help in this work
      with my Greetings and thanks in advance
    • Subz
      By Subz
      Hello all.
      in the process of packaging an application (Voip) and looking at trying to automate capturing the following information to add to a config.xml file:
      Default: Playback Device Name and Guid
      Example:
      Name: Speakers (Realtek High Definition Audio)
      Guid: {0.0.0.00000000}.{a46ce930-4dd3-49b5-8e8e-7c8a2fdc3925}
      Default Microphone Device Name and Guid
      Example:
      Name: Microphone (Realtek High Definition Audio)
      Guid: {0.0.1.00000000}.{cff6f838-33ce-4c2d-9f77-98f4e19e4a75}
      I've seen the following post by @trancexx, which gives me the Default Audit Device Name, but unsure how to get the Guid or the Microphone Name and Guid.  I believe to get the Guid, I would need to use PKEY_AudioEndpoint_GUID but unsure how to code this.  If anyone can assist or point me in the right direction it would be much appreciated.
      Cheers Subz
       
    • nacerbaaziz
      By nacerbaaziz
      Hi guys
      I'm looking for how to detect if the default audio output has changed
      During my research I found this file
      I did not know how to use it
      can  anyone guide me how  it works please.
      Thanks in advance
      audioOutputIsChanged.au3
×