2012-04-01 13 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]; 



} 

それは実行時エラーを報告しています:、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

答えて

6

は、XcodeでAudioToolboxのlibが必ず含めてください。ファイルがインポートされたがライブラリをプロジェクトにリンクしていないため、同じエラーが発生しました。

これはあなたが持っているエラーを取り除くべきです。

楽しい一日を!

関連する問題