30 BOOL savedGame; |
31 BOOL savedGame; |
31 // cache the grenade time |
32 // cache the grenade time |
32 NSInteger grenadeTime; |
33 NSInteger grenadeTime; |
33 // the reference to the newMenu instance |
34 // the reference to the newMenu instance |
34 AmmoMenuViewController *amvc_instance; |
35 AmmoMenuViewController *amvc_instance; |
|
36 // the audiosession must be initialized before using properties |
|
37 BOOL gAudioSessionInited = NO; |
35 |
38 |
36 #pragma mark - |
39 #pragma mark - |
37 #pragma mark functions called like oop |
40 #pragma mark functions called like oop |
38 void objcExportsInit() { |
41 void objcExportsInit() { |
39 gameRunning = NO; |
42 gameRunning = NO; |
149 |
152 |
150 void updateVisualsNewTurn(void) { |
153 void updateVisualsNewTurn(void) { |
151 DLog(@"updating visuals"); |
154 DLog(@"updating visuals"); |
152 [amvc_instance updateAmmoVisuals]; |
155 [amvc_instance updateAmmoVisuals]; |
153 } |
156 } |
|
157 |
|
158 // http://stackoverflow.com/questions/287543/how-to-programatically-sense-the-iphone-mute-switch |
|
159 BOOL isAppleDeviceMuted(void) { |
|
160 if (!gAudioSessionInited) { |
|
161 AudioSessionInterruptionListener inInterruptionListener = NULL; |
|
162 OSStatus error; |
|
163 if ((error = AudioSessionInitialize (NULL, NULL, inInterruptionListener, NULL))) |
|
164 DLog(@"*** Error *** error in AudioSessionInitialize: %d", error); |
|
165 else |
|
166 gAudioSessionInited = YES; |
|
167 } |
|
168 UInt32 propertySize = sizeof(CFStringRef); |
|
169 |
|
170 // this checks if there is volume |
|
171 Float32 volume; |
|
172 OSStatus n = AudioSessionGetProperty(kAudioSessionProperty_CurrentHardwareOutputVolume, &propertySize, &volume); |
|
173 if (n != 0) |
|
174 DLog( @"AudioSessionGetProperty: %d", n ); |
|
175 BOOL volumeResult = (volume == 0.0); |
|
176 |
|
177 // this checks if the device is muted |
|
178 CFStringRef state; |
|
179 n = AudioSessionGetProperty(kAudioSessionProperty_AudioRoute, &propertySize, &state); |
|
180 if (n != 0) |
|
181 DLog( @"AudioSessionGetProperty: %d", n ); |
|
182 NSString *result = (NSString *)state; |
|
183 BOOL muteResult = ([result length] == 0); |
|
184 releaseAndNil(result); |
|
185 |
|
186 return volumeResult || muteResult; |
|
187 } |