@@ -18,8 +18,7 @@ internal static float GetSpotifyVolume()
1818 throw new COMException ( "Volume object creation failed" ) ;
1919 }
2020
21- float level ;
22- volume . GetMasterVolume ( out level ) ;
21+ volume . GetMasterVolume ( out float level ) ;
2322 Marshal . ReleaseComObject ( volume ) ;
2423 return level * 100 ;
2524 }
@@ -33,8 +32,7 @@ internal static bool IsSpotifyMuted()
3332 throw new COMException ( "Volume object creation failed" ) ;
3433 }
3534
36- bool mute ;
37- volume . GetMute ( out mute ) ;
35+ volume . GetMute ( out bool mute ) ;
3836 Marshal . ReleaseComObject ( volume ) ;
3937 return mute ;
4038 }
@@ -79,12 +77,10 @@ private static ISimpleAudioVolume GetSpotifyVolumeObject()
7977 private static ISimpleAudioVolume GetVolumeObject ( int pid )
8078 {
8179 // get the speakers (1st render + multimedia) device
82- IMmDeviceEnumerator deviceEnumerator = ( IMmDeviceEnumerator ) ( new MMDeviceEnumerator ( ) ) ;
83- IMmDevice speakers ;
84- deviceEnumerator . GetDefaultAudioEndpoint ( EDataFlow . ERender , ERole . EMultimedia , out speakers ) ;
80+ IMmDeviceEnumerator deviceEnumerator = ( IMmDeviceEnumerator ) new MMDeviceEnumerator ( ) ;
81+ deviceEnumerator . GetDefaultAudioEndpoint ( EDataFlow . ERender , ERole . EMultimedia , out IMmDevice speakers ) ;
8582
86- string defaultDeviceId ;
87- speakers . GetId ( out defaultDeviceId ) ;
83+ speakers . GetId ( out string defaultDeviceId ) ;
8884
8985 ISimpleAudioVolume volumeControl = GetVolumeObject ( pid , speakers ) ;
9086 Marshal . ReleaseComObject ( speakers ) ;
@@ -97,18 +93,13 @@ private static ISimpleAudioVolume GetVolumeObject(int pid)
9793 // As far as Spotify is concerned, if using the "--enable-audio-graph" command line argument,
9894 // a new option becomes available in the Settings that makes it possible to change the playback device.
9995
100- IMmDeviceCollection deviceCollection ;
101- deviceEnumerator . EnumAudioEndpoints ( EDataFlow . ERender , EDeviceState . Active , out deviceCollection ) ;
96+ deviceEnumerator . EnumAudioEndpoints ( EDataFlow . ERender , EDeviceState . Active , out IMmDeviceCollection deviceCollection ) ;
10297
103- int count ;
104- deviceCollection . GetCount ( out count ) ;
98+ deviceCollection . GetCount ( out int count ) ;
10599 for ( int i = 0 ; i < count ; i ++ )
106100 {
107- IMmDevice device ;
108- deviceCollection . Item ( i , out device ) ;
109-
110- string deviceId ;
111- device . GetId ( out deviceId ) ;
101+ deviceCollection . Item ( i , out IMmDevice device ) ;
102+ device . GetId ( out string deviceId ) ;
112103
113104 try
114105 {
@@ -134,29 +125,24 @@ private static ISimpleAudioVolume GetVolumeObject(int pid, IMmDevice device)
134125 {
135126 // activate the session manager. we need the enumerator
136127 Guid iidIAudioSessionManager2 = typeof ( IAudioSessionManager2 ) . GUID ;
137- object o ;
138- device . Activate ( ref iidIAudioSessionManager2 , 0 , IntPtr . Zero , out o ) ;
139- IAudioSessionManager2 mgr = ( IAudioSessionManager2 ) o ;
128+ device . Activate ( ref iidIAudioSessionManager2 , 0 , IntPtr . Zero , out object o ) ;
129+ IAudioSessionManager2 mgr = ( IAudioSessionManager2 ) o ;
140130
141131 // enumerate sessions for on this device
142- IAudioSessionEnumerator sessionEnumerator ;
143- mgr . GetSessionEnumerator ( out sessionEnumerator ) ;
144- int count ;
145- sessionEnumerator . GetCount ( out count ) ;
132+ mgr . GetSessionEnumerator ( out IAudioSessionEnumerator sessionEnumerator ) ;
133+ sessionEnumerator . GetCount ( out int count ) ;
146134
147135 // search for an audio session with the required name
148136 // NOTE: we could also use the process id instead of the app name (with IAudioSessionControl2)
149137 ISimpleAudioVolume volumeControl = null ;
150138 for ( int i = 0 ; i < count ; i ++ )
151139 {
152- IAudioSessionControl2 ctl ;
153- sessionEnumerator . GetSession ( i , out ctl ) ;
154- int cpid ;
155- ctl . GetProcessId ( out cpid ) ;
140+ sessionEnumerator . GetSession ( i , out IAudioSessionControl2 ctl ) ;
141+ ctl . GetProcessId ( out int cpid ) ;
156142
157143 if ( cpid == pid )
158144 {
159- volumeControl = ( ISimpleAudioVolume ) ctl ;
145+ volumeControl = ( ISimpleAudioVolume ) ctl ;
160146 break ;
161147 }
162148 Marshal . ReleaseComObject ( ctl ) ;
0 commit comments