In iOS 5, How to use AudioSession to make sure that sound is played through the speaker even though the earphone is connected?

- (void)viewDidLoad { [super viewDidLoad]; NSString *filePath = [[NSBundle mainBundle] pathForResource:@"1" ofType:@"mp3"]; // Convert the file path to a URL. NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:filePath]; [[AVAudioSession sharedInstance] setDelegate: self]; UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker; AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute,sizeof (audioRouteOverride),&audioRouteOverride); //Initialize the AVAudioPlayer. self.audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:nil]; self.audioPlayer.volume = 1.0; // Preloads the buffer and prepares the audio for playing. [self.audioPlayer prepareToPlay]; } 

it reports a runtime error:

 Undefined symbols for architecture armv7: "_AudioSessionSetProperty", referenced from: -[SoundTesterViewController viewDidLoad] in SoundTesterViewController.o ld: symbol(s) not found for architecture armv7 clang: error: linker command failed with exit code 1 (use -v to see invocation) 
+4
ios objective-c ios5
source share
1 answer

Be sure to enable AudioToolbox lib in xCode. I had the same error because the files were imported but did not link the library to the project.

This should get rid of your existing error.

Have a nice day!

+6
source share

All Articles