I know this question has been asked many times, and I checked most of the answers related to SO, but I was not lucky to find the correct answer to my problem.
Here is the problem:
I tried to play an mp3 file (maximum 2 seconds) in the game when some event is triggered, and I use AudioPlayer for this, below are the blocks of code:
NSError *error; AVAudioPlayer *audioPlayer = [[[AVAudioPlayer alloc] initWithContentsOfURL:[[NSBundle mainBundle] URLForResource: @"ding" withExtension: @"mp3"] error:&error] autorelease]; if (error) { NSLog(@"Error creating audio player: %@", [error userInfo]); } else { BOOL success = [audioPlayer play];
When I ran this code on the iPhone 4s, iTouch 3/4, the sound always sounded good and clear, but on the iPad 1 or iPad2 there is no sound from the speaker. But when I connected the headphones, it was strange that a sound was heard from my headphones! The iPad is not in mute mode, and the URL is correct.
I am confused why this happened.
PS: I tried the following code (obtained from HERE ) to output the type of audio output signal:
CFDictionaryRef asCFType = nil; UInt32 dataSize = sizeof(asCFType); AudioSessionGetProperty(kAudioSessionProperty_AudioRouteDescription, &dataSize, &asCFType); NSDictionary *easyPeasy = (NSDictionary *)asCFType; NSDictionary *firstOutput = (NSDictionary *)[[easyPeasy valueForKey:@"RouteDetailedDescription_Outputs"] objectAtIndex:0]; NSString *portType = (NSString *)[firstOutput valueForKey:@"RouteDetailedDescription_PortType"]; NSLog(@"first output port type is: %@!", portType);
When I plugged in the headphones, the output was "the first type of output port is headphones!" And when I turned it off, the output turned out to be the first type of speaker output port! "
It would be great if someone could offer some help or advice.