The following function is based on some info I found scattered around on forums, as well as some of my own tinkering to actually get it to work. It will return a boolean indicating if you will be able to play audio using the AVAudioPlayer.
- (bool)isAudioEnabled {
UInt32 cfRouteSize = sizeof (CFStringRef);
CFStringRef cfRoute;
NSString* nsRoute;
AudioSessionGetProperty(
kAudioSessionProperty_AudioRoute,
&cfRouteSize,
&cfRoute);
nsRoute = (NSString*)cfRoute;
return ([nsRoute length] == 0);
}
Note: If the iPhone is in Silent mode with headphones attached, this function will return true, and the AVAudioPlayer should still be able to play audio.
0 comments:
Post a Comment