IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Contribuez .NET Discussion :

[VB.NET]Comment controler le Volume/Mute d'une ligne audio? [Sources]


Sujet :

Contribuez .NET

  1. #1
    Nouveau membre du Club
    Inscrit en
    Décembre 2005
    Messages
    61
    Détails du profil
    Informations forums :
    Inscription : Décembre 2005
    Messages : 61
    Points : 28
    Points
    28
    Par défaut [VB.NET]Comment controler le Volume/Mute d'une ligne audio?
    Bonjour, étant donner qu'il n'y a quasiement aucun code de ce type sur la toile, et peut-être aucun en VB.NEt, je me devais de le mettre en ligne.

    Voici un module, permettant de modifier le volume/mute, ou de connaitre leurs valeurs actuelles, de n'importe quelle ligne audio de vos cartes sons.
    Attention: Seules les lignes audio comportant un contrôle Mute peuvent être modifié/lu. Les lignes d'enregistrement, avec une option "sélection" ne le peuvent pas! Il faudrai modifier ce code pour celà

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
     
    Public Module Sound
     
    		#Region "MIXERLINE_COMPONENTTYPE"
    			Public Enum MIXERLINE_COMPONENTTYPE 
    				DST_FIRST       = &H0
    				DST_SPEAKERS    = (DST_FIRST + 4)
     
    				SRC_FIRST       = &H00001000
    				SRC_UNDEFINED   = (SRC_FIRST + 0)
    				SRC_DIGITAL     = (SRC_FIRST + 1)
    				SRC_LINE        = (SRC_FIRST + 2)
    				SRC_MICROPHONE  = (SRC_FIRST + 3)
    				SRC_SYNTHESIZER = (SRC_FIRST + 4)
    				SRC_COMPACTDISC = (SRC_FIRST + 5)
    				SRC_TELEPHONE   = (SRC_FIRST + 6)
    				SRC_PCSPEAKER   = (SRC_FIRST + 7)
    				SRC_WAVEOUT     = (SRC_FIRST + 8)
    				SRC_AUXILIARY   = (SRC_FIRST + 9)
    				SRC_ANALOG      = (SRC_FIRST + 10)
    				SRC_LAST        = (SRC_FIRST + 10)
    			End Enum
    		#End Region
     
    		#Region "Constants"
    		    Friend Const MMSYSERR_NOERROR As Integer = 0
    		    Friend Const MMSYSERR_BASE = 0
    		    Friend Const MMSYSERR_BADDEVICEID = (MMSYSERR_BASE + 2)
    		    Friend Const MMSYSERR_INVALFLAG = (MMSYSERR_BASE + 10)
    		    Friend Const MMSYSERR_INVALHANDLE = (MMSYSERR_BASE + 5)
    		    Friend Const MMSYSERR_INVALPARAM = (MMSYSERR_BASE + 11)
    		    Friend Const MMSYSERR_NODRIVER = (MMSYSERR_BASE + 6)
    		    Friend Const MAXPNAMELEN As Integer = 32
    		    Friend Const MIXER_LONG_NAME_CHARS As Integer = 64
    		    Friend Const MIXER_SHORT_NAME_CHARS As Integer = 16
    		    Friend Const MIXERCONTROL_CT_CLASS_FADER As Integer = &H50000000
    		    Friend Const MIXERCONTROL_CT_UNITS_UNSIGNED As Integer = &H30000
    		    Friend Const MIXERCONTROL_CT_UNITS_BOOLEAN As Integer = &H10000
    		    Friend Const MIXERCONTROL_CT_CLASS_SWITCH As Integer = &H20000000
    		    Friend Const MIXERCONTROL_CONTROLTYPE_FADER As Integer = (MIXERCONTROL_CT_CLASS_FADER Or MIXERCONTROL_CT_UNITS_UNSIGNED)
    		    Friend Const MIXERCONTROL_CONTROLTYPE_VOLUME As Integer = (MIXERCONTROL_CONTROLTYPE_FADER + 1)
    		    Friend Const MIXER_GETLINEINFOF_COMPONENTTYPE As Integer = &H3&
    		    Friend Const MIXER_GETLINECONTROLSF_ONEBYTYPE As Integer = &H2
    		    Friend Const MIXERCONTROL_CONTROLTYPE_BASS As Integer = (MIXERCONTROL_CONTROLTYPE_FADER + 2)
    		    Friend Const MIXERCONTROL_CONTROLTYPE_TREBLE As Integer = (MIXERCONTROL_CONTROLTYPE_FADER + 3)
    		    Friend Const MIXERCONTROL_CONTROLTYPE_EQUALIZER As Integer = (MIXERCONTROL_CONTROLTYPE_FADER + 4)
    		    Friend Const MIXERCONTROL_CONTROLTYPE_BOOLEAN As Integer = (MIXERCONTROL_CT_CLASS_SWITCH Or MIXERCONTROL_CT_UNITS_BOOLEAN)
    		    Friend Const MIXERCONTROL_CONTROLTYPE_MUTE As Integer = (MIXERCONTROL_CONTROLTYPE_BOOLEAN + 2)
    		#End Region
     
    		#Region "Structs"
     
    			Friend Structure MIXERCAPS
    			   Dim wMid As Integer
    			   Dim wPid As Integer
    			   Dim vDriverVersion As Long
    			   Dim szPname As String
    			   Dim fdwSupport As Long
    			   Dim cDestinations As Long
    			End Structure
     
    		    <StructLayout(LayoutKind.Sequential)> _
    		    Friend Structure MIXERCONTROL
    		        <FieldOffset(0)> Public cbStruct As Integer           '  size in Byte of MIXERCONTROL
    		        <FieldOffset(4)> Public dwControlID As Integer        '  unique control id for mixer device
    		        <FieldOffset(8)> Public dwControlType As Integer      '  MIXERCONTROL_CONTROLTYPE_xxx
    		        <FieldOffset(12)> Public fdwControl As Integer         '  MIXERCONTROL_CONTROLF_xxx
    		        <FieldOffset(16)> Public cMultipleItems As Integer     '  if MIXERCONTROL_CONTROLF_MULTIPLE set
    		        <FieldOffset(20), MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst:=MIXER_SHORT_NAME_CHARS)> Public szShortName As String ' * MIXER_SHORT_NAME_CHARS  ' short name of control
    		        <FieldOffset(36), MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst:=MIXER_LONG_NAME_CHARS)> Public szName As String '  * MIXER_LONG_NAME_CHARS ' Integer name of control
    		        <FieldOffset(100)> Public lMinimum As Integer           '  Minimum value
    		        <FieldOffset(104)> Public lMaximum As Integer           '  Maximum value
    		        <FieldOffset(108), MarshalAs(UnmanagedType.ByValArray, SizeConst:=11, ArraySubType:=UnmanagedType.AsAny)> Public reserved() As Integer      '  reserved structure space
    		    End Structure
     
    		    <StructLayout(LayoutKind.Sequential)> _
    		    Friend Structure MIXERCONTROLDETAILS
    		        <FieldOffset(0)> Public cbStruct As Integer       '  size in Byte of MIXERCONTROLDETAILS
    		        <FieldOffset(4)> Public dwControlID As Integer    '  control id to get/set details on
    		        <FieldOffset(8)> Public cChannels As Integer      '  number of channels in paDetails array
    		        <FieldOffset(12)> Public item As Integer           '  hwndOwner or cMultipleItems
    		        <FieldOffset(16)> Public cbDetails As Integer      '  size of _one_ details_XX struct
    		        <FieldOffset(20)> Public paDetails As IntPtr       '  pointer to array of details_XX structs
    		    End Structure
     
    		    <StructLayout(LayoutKind.Sequential)> _
    		    Friend Structure MIXERCONTROLDETAILS_UNSIGNED
    		        <FieldOffset(0)> Public dwValue As Integer        '  value of the control
    		    End Structure
     
    		    <StructLayout(LayoutKind.Sequential)> _
    		    Friend Structure MIXERLINECONTROLS
    		        <FieldOffset(0)> Public cbStruct As Integer       '  size in Byte of MIXERLINECONTROLS
    		        <FieldOffset(4)> Public dwLineID As Integer       '  line id (from MIXERLINE.dwLineID)
    		        <FieldOffset(8)> Public dwControl As Integer      '  MIXER_GETLINECONTROLSF_ONEBYTYPE
    		        <FieldOffset(12)> Public cControls As Integer      '  count of controls pmxctrl points to
    		        <FieldOffset(16)> Public cbmxctrl As Integer       '  size in Byte of _one_ MIXERCONTROL
    		        <FieldOffset(20)> Public pamxctrl As IntPtr       '  pointer to first MIXERCONTROL array
    		    End Structure
     
    		    <StructLayout(LayoutKind.Sequential)> _
    		    Friend Structure MIXERLINE
    		        <FieldOffset(0)> Public cbStruct As Integer                '  size of MIXERLINE structure
    		        <FieldOffset(4)> Public dwDestination As Integer          '  zero based destination index
    		        <FieldOffset(8)> Public dwSource As Integer               '  zero based source index (if source)
    		        <FieldOffset(12)> Public dwLineID As Integer               '  unique line id for mixer device
    		        <FieldOffset(16)> Public fdwLine As Integer                '  state/information about line
    		        <FieldOffset(20)> Public dwUser As Integer                 '  driver specific information
    		        <FieldOffset(24)> Public dwComponentType As Integer        '  component type line connects to
    		        <FieldOffset(28)> Public cChannels As Integer              '  number of channels line supports
    		        <FieldOffset(32)> Public cConnections As Integer           '  number of connections (possible)
    		        <FieldOffset(36)> Public cControls As Integer              '  number of controls at this line
    		        <FieldOffset(40), MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst:=MIXER_SHORT_NAME_CHARS)> Public szShortName As String  ' * MIXER_SHORT_NAME_CHARS
    		        <FieldOffset(56), MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst:=MIXER_LONG_NAME_CHARS)> Public szName As String ' * MIXER_LONG_NAME_CHARS
    		        <FieldOffset(120)> Public dwType As Integer
    		        <FieldOffset(124)> Public dwDeviceID As Integer
    		        <FieldOffset(128)> Public wMid As Integer
    		        <FieldOffset(132)> Public wPid As Integer
    		        <FieldOffset(136)> Public vDriverVersion As Integer
    		        <FieldOffset(135), MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst:=MAXPNAMELEN)> Public szPname As String ' * MAXPNAMELEN
    		    End Structure
     
    		#End Region
     
    		#Region "API Declarations"
    			Friend Declare Function mixerGetNumDevs Lib "winmm.dll" () As Integer
    		    Friend Declare Function mixerGetLineControls Lib "winmm.dll" Alias "mixerGetLineControlsA" (<MarshalAs(UnmanagedType.I4)> ByVal hmxobj As Integer, ByRef pmxlc As MIXERLINECONTROLS, ByVal fdwControls As Integer) As Integer
    		    Friend Declare Function mixerSetControlDetails Lib "winmm.dll" (<MarshalAs(UnmanagedType.I4)> ByVal hmxobj As Integer,ByRef pmxcd As MIXERCONTROLDETAILS, ByVal fdwDetails As Integer) As Integer
    			Friend Declare Function mixerGetLineInfo Lib "winmm.dll" Alias "mixerGetLineInfoA" (<MarshalAs(UnmanagedType.I4)> ByVal hmxobj As Integer, ByRef pmxl As MIXERLINE, ByVal fdwInfo As Integer) As Integer
    			Friend Declare Function mixerOpen Lib "winmm.dll" (ByRef phmx As Integer, <MarshalAs(UnmanagedType.U4)> ByVal uMxId As Integer, ByVal dwCallback As Integer, ByVal dwInstance As Integer, ByVal fdwOpen As Integer) As Integer
    			Friend Declare Function mixerClose Lib "winmm.dll" (hm As Integer) As Integer
    			Friend Declare Function mixerGetControlDetails Lib "winmm.dll" Alias "mixerGetControlDetailsA" (<MarshalAs(UnmanagedType.I4)> ByVal hmxobj As Integer, ByRef pmxcd As MIXERCONTROLDETAILS, ByVal fdwDetails As Integer) As Integer
    		#End Region
     
     
    		Public Class Device
     
     
    			Public Dim Handle As Integer
    			Public Dim ID As Integer
    			Public Dim Name As String
     
     
    			Private Sub CreateDevice(ByVal Identity As String)
    'Cette partie sert à Trouver la carte son correspondant à l'identity demandé, et à enregistrer son handle dans Handle
    'L'Identity peut être un string (le nom de carte audio) ou le DeviceID de la carte son.
    'Le DeviceID part de 0 (0 étant la carte son configuré actuellement dasn windows XP) et va jusqu'à votre derniere carte son
     
     
    				Dim lngReturn As Integer
    				Dim i As Integer
    				Dim rc As Integer
    				Dim DeviceID As Integer
    				Dim DeviceName As String = ""
    				Dim MixerLine As MIXERLINE
     
    				Try
    					If CInt(Identity) >= 0 Then
    						DeviceID = CInt(Identity) + 1 
    					Else
    						Exit Sub
    					End If
    				Catch
    					DeviceName = Identity
    				Finally
    				End Try
     
    				Do
    					mixerClose(Handle)
    					MixerLine = New MIXERLINE
     
    					' Obtain the Handle struct
    			        lngReturn = mixerOpen(Handle, i, 0, 0, 0)
    					i=i+1
     
    			        ' Error check
     
    			        If lngReturn <> 0 And i > mixerGetNumDevs()+7 Then
    			        	mixerClose(Handle)
    			        	Dim ex As New Exception("No one SoundDevice corresponds to DeviceID/DeviceName indicated!") 
    						Throw  ex
    			        	Exit Sub
    			        End If
     
    			        MixerLine.cbStruct = Marshal.SizeOf(MixerLine)
    			        MixerLine.dwComponentType = MIXERLINE_COMPONENTTYPE.DST_SPEAKERS
     
    			        ' Obtain a line corresponding to the component type
    			        rc = mixerGetLineInfo(Handle, MixerLine, MIXER_GETLINEINFOF_COMPONENTTYPE)
    				Loop Until MMSYSERR_NOERROR = rc and (DeviceID = MixerLine.dwDeviceID+1 Or DeviceName Like "*" & MixerLine.szPname & "*")
    				ID = MixerLine.dwDeviceID
    				Name = MixerLine.szPname
     
    			End Sub
     
    			Public Sub New(ByVal DeviceID As Integer)
    		        Me.CreateDevice(DeviceID)
    			End Sub
     
    			Public Sub New(ByVal DeviceName As String)
    			 	Me.CreateDevice(DeviceName)
    			End Sub
     
     
    			Private Function GetControl(ByVal MixerLine As MIXERLINE ,ByVal ControlType As Integer) As MIXERCONTROL
    				Dim rc As Integer
    				Dim mxlc As New MIXERLINECONTROLS
    				Dim Control As New MIXERCONTROL
    				Dim pmem As IntPtr
     
     
    	            mxlc.cbStruct = Marshal.SizeOf(mxlc)
    	            mxlc.dwLineID = MixerLine.dwLineID
    	            mxlc.dwControl = ControlType
    	            mxlc.cControls = 0
    	            mxlc.cbmxctrl = Marshal.SizeOf(Control)
     
    	            ' Allocate a buffer for the control
    	            pmem = Marshal.AllocHGlobal(Marshal.SizeOf(Control))
    	            mxlc.pamxctrl = pmem
     
    	            Control.cbStruct = Marshal.SizeOf(Control)
     
    	            ' Get the control
    	            rc = mixerGetLineControls(Handle, mxlc, MIXER_GETLINECONTROLSF_ONEBYTYPE)
     
    	            If (MMSYSERR_NOERROR = rc) Then
    	                Control = CType(Marshal.PtrToStructure(mxlc.pamxctrl, GetType(MIXERCONTROL)), MIXERCONTROL)
    	            Else
    	            	Dim ex As New Exception("No one Control corresponds to ControlIndex indicated!")
    					Throw  ex
    					Exit Function
    	            End If
     
    	            Marshal.FreeHGlobal(pmem)
    	            Return Control
    			End Function 
     
    			Public Function GetLine(ByVal iComponentType As Integer) As Line
    				Dim MixerLine As New MIXERLINE
    				Dim rc As Integer
     
    				MixerLine.cbStruct = Marshal.SizeOf(MixerLine)
    		        MixerLine.dwComponentType = iComponentType
     
    		        ' Obtain a line corresponding to the component type
    		        rc = mixerGetLineInfo(Handle, MixerLine, MIXER_GETLINEINFOF_COMPONENTTYPE)
     
    		        If (MMSYSERR_NOERROR = rc) Then
    		        	Dim LineMx As New Line
    		            LineMx.VolCtrl = GetControl(MixerLine, MIXERCONTROL_CONTROLTYPE_VOLUME)
    		            LineMx.MuteCtrl = GetControl(MixerLine, MIXERCONTROL_CONTROLTYPE_MUTE)
    		            LineMx.DeviceHandle = Handle
    		            LineMx.Name = MixerLine.szName
    		            Return LineMx
    	            Else
    	            	Dim ex As New Exception("No one Line corresponds with Component Type indicated!")
    					Throw  ex
    	            End If
     
    			End Function
     
     
    		End Class
     
    		Public Class Line
     
    			Public Dim DeviceHandle As Integer
    			Public Dim Name As String
    			Friend Dim MuteCtrl As MIXERCONTROL
    			Friend Dim VolCtrl As MIXERCONTROL
     
    			Public Sub SetVolume(ByVal Level As Integer)
     
    		        If not (Level >= 0 And Level <= 100) Then
    		        	Dim ex As New Exception("Level is not between 0 and 100") 
    					Throw  ex
    		        End If
     
    		        ' Then determine the value of the volume and Set the volume!
    		        Call SetParameter(VolCtrl,CType(volCtrl.lMaximum * (Level / 100), Integer))
     
    			End Sub
     
    			Public Sub SetMute(ByVal boolMute As Boolean)
     
    		        ' Then determine the value of the volume
    		        If boolMute Then
    		            ' Mute
    		            Call SetParameter(MuteCtrl,1)
    		        Else
    		            ' Turn the sound on
    		            Call SetParameter(MuteCtrl,0)
    		        End If
     
    			End Sub
     
    			Private Sub SetParameter(ByVal Control As MIXERCONTROL,ByVal Parameter As Integer)
    				Dim rc As Integer
     
    				Dim mxcd As MIXERCONTROLDETAILS
    		        Dim vol As MIXERCONTROLDETAILS_UNSIGNED
    		        Dim hptr As IntPtr
     
    				mxcd.item = 0
    		        mxcd.dwControlID = Control.dwControlID
    		        mxcd.cbStruct = Marshal.SizeOf(mxcd)
    		        mxcd.cbDetails = Marshal.SizeOf(vol)
     
    		        hptr = Marshal.AllocHGlobal(Marshal.SizeOf(vol))
     
    		        ' Allocate a buffer for the control value buffer
    		        mxcd.paDetails = hptr
    		        mxcd.cChannels = 1
    		        vol.dwValue = Parameter
     
    		        Marshal.StructureToPtr(vol, hptr, False)
     
    		        ' Set the control value
    		        rc = mixerSetControlDetails(DeviceHandle,mxcd, 0)
     
    		        Marshal.FreeHGlobal(hptr)
     
    			End Sub
     
    			Private Function GetParameter(ByVal Control As MIXERCONTROL) As Integer
    				Dim rc As Integer
     
    				Dim mxcd As MIXERCONTROLDETAILS
    		        Dim vol As MIXERCONTROLDETAILS_UNSIGNED
    		        Dim hptr As IntPtr
     
    				mxcd.item = 0
    		        mxcd.dwControlID = Control.dwControlID
    		        mxcd.cbStruct = Marshal.SizeOf(mxcd)
    		        mxcd.cbDetails = Marshal.SizeOf(vol)
     
    		        hptr = Marshal.AllocHGlobal(Marshal.SizeOf(vol))
     
    		        ' Allocate a buffer for the control value buffer
    		        mxcd.paDetails = hptr
    		        mxcd.cChannels = 1
     
    		        Marshal.StructureToPtr(vol, hptr, False)
     
    		        ' Obtenir les détails du controle
    		        rc = mixerGetControlDetails(DeviceHandle,mxcd, 0)
     
    		        vol = CType(Marshal.PtrToStructure(mxcd.paDetails, GetType(MIXERCONTROLDETAILS_UNSIGNED)), MIXERCONTROLDETAILS_UNSIGNED)
     
    		        Marshal.FreeHGlobal(hptr)
     
    		        ' Retour du paramètre!
    		        Return vol.dwValue
     
    			End Function
     
    			Public Function GetVolume() As Integer
     
    		        ' Retour du volume en cours!
    		        Return CType((GetParameter(VolCtrl)*100)/volCtrl.lMaximum, Integer)
     
    			End Function
     
    			Public Function GetMute() As Boolean
     
    		        ' Retour de la Valeur du Mute en cours!
    		        If GetParameter(MuteCtrl) = 1 Then
    		            Return True
    		        Else
    		            Return False
    		        End If
     
    			End Function
     
     
     
    		End Class
     
    	End Module
    Les sources du module, pour pouvoir les lire confortablement dans votre environnement de travail
    http://jazzmatazz.free.fr/Sound.rar


    Class -> Device

    _ Sub New(ByVal DeviceID As Integer) -> Construit à partir du numéro de Device, celui ci étant 0 pour la carte audio actuellement configuré dans Windows, et allant jusqu à votre dernier carte audio de votre systeme.
    _ Sub New(ByVal DeviceName As String) -> Construit à partir du nom de votre carte audio. Le nom doit être AU MOINS mis en entier! Si vous en mettez plus, ça marchera quand même
    _ Handle
    _ ID
    _ Name
    _ Function GetLine(ByVal iComponentType As Integer) As Line -> Obtient une ligne audio à partir du Component Type, décrit en tout début du code colé à "#Region "MIXERLINE_COMPONENTTYPE"".

    Class -> Line

    _ DeviceHandle -> Donne le Handle de l'audio device contenant la line considéré.
    _ Name
    _ Sub SetVolume(ByVal Level As Integer) -> Met le volume de la ligne, au level indiqué (de 0 à 100)
    _ Sub SetMute(ByVal boolMute As Boolean) -> Mutte ou demutte (True/False) la ligne considéré
    _ Function GetVolume() As Integer -> Retourne la valeur actuelle du volume de la ligne considéré (de 0 à 100).
    _ Function GetMute() As Boolean -> Retourne l'état du mute de la ligne audio considéré.


    Puis une démonstration, ainsi que la Dll pour l'utiliser sans comprendre
    http://jazzmatazz.free.fr/Sound%20D%e9mo%20&%20dll.rar

    Dans la winform de la démonstration, dans le champ "Device", vous pouvez entrez soit le DeviceID de votre carte audio, soit le nom de votre carte audio.Ensuite le champ "Line" doit comprendre le numéro du component type correspondant (voir au dessus). 4 par exemple correspond au MasterVolume.
    Puis cliquez sur "Initialize"...

    Je préviens, c est tres TRES chiant à comprendre! Je n'ai pas compris à 100% ce code, mais en majorité maintenant quand même!
    C'est pour cette raison qu'il m'a paru utile de le mettre en ligne

    Mais même si vous n'y comprenez rien, il est TRES simple d'utiliser ce module! Copiez le dans votre program, ou importer la Dll mise à disposition, et vous pourrez utiliser ces méthodes pour lire/modifier le volume/mute de vos lignes audio de vos cartes sons!

    Bye, bye

  2. #2
    Expert éminent
    Avatar de neguib
    Profil pro
    Inscrit en
    Mai 2005
    Messages
    3 627
    Détails du profil
    Informations personnelles :
    Âge : 64
    Localisation : Suisse

    Informations forums :
    Inscription : Mai 2005
    Messages : 3 627
    Points : 7 879
    Points
    7 879
    Par défaut
    Merci de ta contribution jazz matazz

  3. #3
    Nouveau membre du Club
    Inscrit en
    Décembre 2005
    Messages
    61
    Détails du profil
    Informations forums :
    Inscription : Décembre 2005
    Messages : 61
    Points : 28
    Points
    28
    Par défaut
    Citation Envoyé par neguib
    Merci de ta contribution jazz matazz
    Merci à toi t'es fou ou quoi?!

    Il manque de bon code en VB.NET, même en C# d'ailleurs! LEs developpeurs, qui ont solutionnés quelques choses de ardus en général, sont bien content, et ne prenent pas le temps de partager leurs sources, et d'expliquer leurs trouvailles!
    Mais ça change petit à petit, faut se construire une bibliothèque de codes à tout faire

  4. #4
    Nouveau membre du Club
    Inscrit en
    Décembre 2005
    Messages
    61
    Détails du profil
    Informations forums :
    Inscription : Décembre 2005
    Messages : 61
    Points : 28
    Points
    28
    Par défaut
    J'ai amélioré un peu la chose!

    On peut maintenant obtenir le numéro de device par rapport au nom de la carte, ou le nom de la carte par rapport au device.
    La mise à jour de la class est compris dans le premier post!

  5. #5
    Membre averti Avatar de vdumont
    Profil pro
    Étudiant
    Inscrit en
    Février 2006
    Messages
    510
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : Canada

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Février 2006
    Messages : 510
    Points : 369
    Points
    369
    Par défaut
    Est-ce que les sources sont inclus dans le .rar? Ca se lirait beaucoup mieux dans un éditeur que dans les balises code.

  6. #6
    Expert éminent
    Avatar de neguib
    Profil pro
    Inscrit en
    Mai 2005
    Messages
    3 627
    Détails du profil
    Informations personnelles :
    Âge : 64
    Localisation : Suisse

    Informations forums :
    Inscription : Mai 2005
    Messages : 3 627
    Points : 7 879
    Points
    7 879
    Par défaut
    Tu pourrais très facilement alléger ton code en evitant la redondance des instructions dans les constructeurs et dans les fonctions GetDeviceID et GetDeviceName

  7. #7
    Nouveau membre du Club
    Inscrit en
    Décembre 2005
    Messages
    61
    Détails du profil
    Informations forums :
    Inscription : Décembre 2005
    Messages : 61
    Points : 28
    Points
    28
    Par défaut
    Citation Envoyé par vdumont
    Est-ce que les sources sont inclus dans le .rar? Ca se lirait beaucoup mieux dans un éditeur que dans les balises code.
    Yes, il y a les sources daans le .rar.
    C'est clair que c'est dur à lire! MAis c est incroyablement simple à utiliser sinon en class!
    J'ai laissé le code en entier entre les balises, pour les recherches sur google. C'est important pour que le plus de monde possible puisse trouver les mots clefs du code.

    Citation Envoyé par neguib
    Tu pourrais très facilement alléger ton code en evitant la redondance des instructions dans les constructeurs et dans les fonctions GetDeviceID et GetDeviceName
    Oui, je devrais le faire, je le ferai demain, quand j aurai un moment!

  8. #8
    Nouveau membre du Club
    Inscrit en
    Décembre 2005
    Messages
    61
    Détails du profil
    Informations forums :
    Inscription : Décembre 2005
    Messages : 61
    Points : 28
    Points
    28
    Par défaut
    Voilà! J'ai simplifié le code, mais j y ai ajouté des fonctions!
    On peut maintenant changer n importe quelle ligne audio de n importe quelle carte son!
    J ai completement reédité le premier post, en espérant plus clarifier le tout!
    Par gain de temps, je n ai pas trop commenté le code par contre Mais ça a été ma seule féniantise
    Vous avez un module, un fichier dll pour les fénéants (comme moi donc ), un executable de démonstration, et des explications sur les méthodes!

    Tiens d'ailleurs, en cherchant toutes les valeurs des variables de type "MIXERLINE _COMPONENTTYPE" je suis tombé sur UN code ressemblant réellement à ça! MAis en C#. Son Code est bien plus complet! Et permet de controler aussi les balances, et carrément tout en fait
    http://www.codeguru.com/csharp/cshar...le.php/c10931/

Discussions similaires

  1. Réponses: 4
    Dernier message: 08/01/2013, 15h53
  2. Réponses: 0
    Dernier message: 17/06/2011, 10h53
  3. [VB.NET]Comment afficher 1 progressbar lors d'une lecture fichier ?
    Par evlp2004@hotmail.com dans le forum Windows Forms
    Réponses: 2
    Dernier message: 04/05/2006, 09h00
  4. Réponses: 9
    Dernier message: 13/04/2006, 11h40
  5. Réponses: 6
    Dernier message: 16/02/2006, 14h40

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo