@@ -6,11 +6,11 @@ namespace SpotifyAPI.Local
6
6
{
7
7
internal class VolumeMixerControl
8
8
{
9
- private const String SPOTIFY_PROCESS_NAME = "spotify" ;
9
+ private const String SpotifyProcessName = "spotify" ;
10
10
11
11
internal static float GetSpotifyVolume ( )
12
12
{
13
- Process [ ] p = Process . GetProcessesByName ( SPOTIFY_PROCESS_NAME ) ;
13
+ Process [ ] p = Process . GetProcessesByName ( SpotifyProcessName ) ;
14
14
if ( p . Length == 0 )
15
15
throw new Exception ( "Spotify process is not running or was not found!" ) ;
16
16
@@ -19,7 +19,6 @@ internal static float GetSpotifyVolume()
19
19
ISimpleAudioVolume volume = GetVolumeObject ( pid ) ;
20
20
if ( volume == null )
21
21
{
22
- Marshal . ReleaseComObject ( volume ) ;
23
22
throw new COMException ( "Volume object creation failed" ) ;
24
23
}
25
24
@@ -31,7 +30,7 @@ internal static float GetSpotifyVolume()
31
30
32
31
internal static bool IsSpotifyMuted ( )
33
32
{
34
- Process [ ] p = Process . GetProcessesByName ( SPOTIFY_PROCESS_NAME ) ;
33
+ Process [ ] p = Process . GetProcessesByName ( SpotifyProcessName ) ;
35
34
if ( p . Length == 0 )
36
35
throw new Exception ( "Spotify process is not running or was not found!" ) ;
37
36
@@ -40,7 +39,6 @@ internal static bool IsSpotifyMuted()
40
39
ISimpleAudioVolume volume = GetVolumeObject ( pid ) ;
41
40
if ( volume == null )
42
41
{
43
- Marshal . ReleaseComObject ( volume ) ;
44
42
throw new COMException ( "Volume object creation failed" ) ;
45
43
}
46
44
@@ -52,7 +50,7 @@ internal static bool IsSpotifyMuted()
52
50
53
51
internal static void SetSpotifyVolume ( float level )
54
52
{
55
- Process [ ] p = Process . GetProcessesByName ( SPOTIFY_PROCESS_NAME ) ;
53
+ Process [ ] p = Process . GetProcessesByName ( SpotifyProcessName ) ;
56
54
if ( p . Length == 0 )
57
55
throw new Exception ( "Spotify process is not running or was not found!" ) ;
58
56
@@ -61,7 +59,6 @@ internal static void SetSpotifyVolume(float level)
61
59
ISimpleAudioVolume volume = GetVolumeObject ( pid ) ;
62
60
if ( volume == null )
63
61
{
64
- Marshal . ReleaseComObject ( volume ) ;
65
62
throw new COMException ( "Volume object creation failed" ) ;
66
63
}
67
64
@@ -72,7 +69,7 @@ internal static void SetSpotifyVolume(float level)
72
69
73
70
internal static void MuteSpotify ( bool mute )
74
71
{
75
- Process [ ] p = Process . GetProcessesByName ( SPOTIFY_PROCESS_NAME ) ;
72
+ Process [ ] p = Process . GetProcessesByName ( SpotifyProcessName ) ;
76
73
if ( p . Length == 0 )
77
74
throw new Exception ( "Spotify process is not running or was not found!" ) ;
78
75
@@ -81,7 +78,6 @@ internal static void MuteSpotify(bool mute)
81
78
ISimpleAudioVolume volume = GetVolumeObject ( pid ) ;
82
79
if ( volume == null )
83
80
{
84
- Marshal . ReleaseComObject ( volume ) ;
85
81
throw new COMException ( "Volume object creation failed" ) ;
86
82
}
87
83
@@ -93,14 +89,14 @@ internal static void MuteSpotify(bool mute)
93
89
private static ISimpleAudioVolume GetVolumeObject ( int pid )
94
90
{
95
91
// get the speakers (1st render + multimedia) device
96
- IMMDeviceEnumerator deviceEnumerator = ( IMMDeviceEnumerator ) ( new MMDeviceEnumerator ( ) ) ;
97
- IMMDevice speakers ;
98
- deviceEnumerator . GetDefaultAudioEndpoint ( EDataFlow . eRender , ERole . eMultimedia , out speakers ) ;
92
+ IMmDeviceEnumerator deviceEnumerator = ( IMmDeviceEnumerator ) ( new MMDeviceEnumerator ( ) ) ;
93
+ IMmDevice speakers ;
94
+ deviceEnumerator . GetDefaultAudioEndpoint ( EDataFlow . ERender , ERole . EMultimedia , out speakers ) ;
99
95
100
96
// activate the session manager. we need the enumerator
101
- Guid IID_IAudioSessionManager2 = typeof ( IAudioSessionManager2 ) . GUID ;
97
+ Guid iidIAudioSessionManager2 = typeof ( IAudioSessionManager2 ) . GUID ;
102
98
object o ;
103
- speakers . Activate ( ref IID_IAudioSessionManager2 , 0 , IntPtr . Zero , out o ) ;
99
+ speakers . Activate ( ref iidIAudioSessionManager2 , 0 , IntPtr . Zero , out o ) ;
104
100
IAudioSessionManager2 mgr = ( IAudioSessionManager2 ) o ;
105
101
106
102
// enumerate sessions for on this device
@@ -121,7 +117,7 @@ private static ISimpleAudioVolume GetVolumeObject(int pid)
121
117
122
118
if ( cpid == pid )
123
119
{
124
- volumeControl = ctl as ISimpleAudioVolume ;
120
+ volumeControl = ( ISimpleAudioVolume ) ctl ;
125
121
break ;
126
122
}
127
123
Marshal . ReleaseComObject ( ctl ) ;
@@ -142,31 +138,31 @@ private class MMDeviceEnumerator
142
138
143
139
private enum EDataFlow
144
140
{
145
- eRender ,
146
- eCapture ,
147
- eAll ,
148
- EDataFlow_enum_count
141
+ ERender ,
142
+ ECapture ,
143
+ EAll ,
144
+ EDataFlowEnumCount
149
145
}
150
146
151
147
private enum ERole
152
148
{
153
- eConsole ,
154
- eMultimedia ,
155
- eCommunications ,
156
- ERole_enum_count
149
+ EConsole ,
150
+ EMultimedia ,
151
+ ECommunications ,
152
+ ERoleEnumCount
157
153
}
158
154
159
155
[ Guid ( "A95664D2-9614-4F35-A746-DE8DB63617E6" ) , InterfaceType ( ComInterfaceType . InterfaceIsIUnknown ) ]
160
- private interface IMMDeviceEnumerator
156
+ private interface IMmDeviceEnumerator
161
157
{
162
158
int NotImpl1 ( ) ;
163
159
164
160
[ PreserveSig ]
165
- int GetDefaultAudioEndpoint ( EDataFlow dataFlow , ERole role , out IMMDevice ppDevice ) ;
161
+ int GetDefaultAudioEndpoint ( EDataFlow dataFlow , ERole role , out IMmDevice ppDevice ) ;
166
162
}
167
163
168
164
[ Guid ( "D666063F-1587-4E43-81F1-B948E807363F" ) , InterfaceType ( ComInterfaceType . InterfaceIsIUnknown ) ]
169
- private interface IMMDevice
165
+ private interface IMmDevice
170
166
{
171
167
[ PreserveSig ]
172
168
int Activate ( ref Guid iid , int dwClsCtx , IntPtr pActivationParams , [ MarshalAs ( UnmanagedType . IUnknown ) ] out object ppInterface ) ;
@@ -180,30 +176,30 @@ private interface IAudioSessionManager2
180
176
int NotImpl2 ( ) ;
181
177
182
178
[ PreserveSig ]
183
- int GetSessionEnumerator ( out IAudioSessionEnumerator SessionEnum ) ;
179
+ int GetSessionEnumerator ( out IAudioSessionEnumerator sessionEnum ) ;
184
180
}
185
181
186
182
[ Guid ( "E2F5BB11-0570-40CA-ACDD-3AA01277DEE8" ) , InterfaceType ( ComInterfaceType . InterfaceIsIUnknown ) ]
187
183
private interface IAudioSessionEnumerator
188
184
{
189
185
[ PreserveSig ]
190
- int GetCount ( out int SessionCount ) ;
186
+ int GetCount ( out int sessionCount ) ;
191
187
192
188
[ PreserveSig ]
193
- int GetSession ( int SessionCount , out IAudioSessionControl2 Session ) ;
189
+ int GetSession ( int sessionCount , out IAudioSessionControl2 session ) ;
194
190
}
195
191
196
192
[ Guid ( "87CE5498-68D6-44E5-9215-6DA47EF883D8" ) , InterfaceType ( ComInterfaceType . InterfaceIsIUnknown ) ]
197
193
private interface ISimpleAudioVolume
198
194
{
199
195
[ PreserveSig ]
200
- int SetMasterVolume ( float fLevel , ref Guid EventContext ) ;
196
+ int SetMasterVolume ( float fLevel , ref Guid eventContext ) ;
201
197
202
198
[ PreserveSig ]
203
199
int GetMasterVolume ( out float pfLevel ) ;
204
200
205
201
[ PreserveSig ]
206
- int SetMute ( bool bMute , ref Guid EventContext ) ;
202
+ int SetMute ( bool bMute , ref Guid eventContext ) ;
207
203
208
204
[ PreserveSig ]
209
205
int GetMute ( out bool pbMute ) ;
@@ -219,19 +215,19 @@ private interface IAudioSessionControl2
219
215
int GetDisplayName ( [ MarshalAs ( UnmanagedType . LPWStr ) ] out string pRetVal ) ;
220
216
221
217
[ PreserveSig ]
222
- int SetDisplayName ( [ MarshalAs ( UnmanagedType . LPWStr ) ] string Value , [ MarshalAs ( UnmanagedType . LPStruct ) ] Guid EventContext ) ;
218
+ int SetDisplayName ( [ MarshalAs ( UnmanagedType . LPWStr ) ] string value , [ MarshalAs ( UnmanagedType . LPStruct ) ] Guid eventContext ) ;
223
219
224
220
[ PreserveSig ]
225
221
int GetIconPath ( [ MarshalAs ( UnmanagedType . LPWStr ) ] out string pRetVal ) ;
226
222
227
223
[ PreserveSig ]
228
- int SetIconPath ( [ MarshalAs ( UnmanagedType . LPWStr ) ] string Value , [ MarshalAs ( UnmanagedType . LPStruct ) ] Guid EventContext ) ;
224
+ int SetIconPath ( [ MarshalAs ( UnmanagedType . LPWStr ) ] string value , [ MarshalAs ( UnmanagedType . LPStruct ) ] Guid eventContext ) ;
229
225
230
226
[ PreserveSig ]
231
227
int GetGroupingParam ( out Guid pRetVal ) ;
232
228
233
229
[ PreserveSig ]
234
- int SetGroupingParam ( [ MarshalAs ( UnmanagedType . LPStruct ) ] Guid Override , [ MarshalAs ( UnmanagedType . LPStruct ) ] Guid EventContext ) ;
230
+ int SetGroupingParam ( [ MarshalAs ( UnmanagedType . LPStruct ) ] Guid Override , [ MarshalAs ( UnmanagedType . LPStruct ) ] Guid eventContext ) ;
235
231
236
232
[ PreserveSig ]
237
233
int NotImpl1 ( ) ;
0 commit comments