2012-04-01 42 views
4
- (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]; 



} 

它的報告運行時錯誤:在iOS 5中,如何使用AudioSession確保通過揚聲器播放音頻,儘管耳機已插入?

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) 
+0

我有同樣的問題,此代碼工作。 – Madhu 2013-04-17 09:35:38

回答

6

一定要包括Xcode中AudioToolbox庫。我有同樣的錯誤,因爲文件已導入但未將庫鏈接到項目。

這應該擺脫你有錯誤。

有一個愉快的一天!

相關問題