2010-02-16 147 views
0

我只是想讓一個簡單的MP3播放器工作。我收到了一個我不太明白的錯誤。問題播放音頻Iphone

我有AVAudioPlayer實例在我的.h文件聲明,我合成它在我的.m文件....

Undefined symbols: 
    ".objc_class_name_AVAudioPlayer", referenced from: 
     [email protected][email protected][email protected] in PromoTabOptionHome.o 
ld: symbol(s) not found 
collect2: ld returned 1 exit status 

我的.h文件的定義如下

#import <UIKit/UIKit.h> 
#import <AVFoundation/AVFoundation.h> 


@interface PromoTabOptionHome : UIViewController { 

    UIButton *playPause; 
    AVAudioPlayer* audioPlayer; 
    NSMutableString *audioPath; 
    BOOL playing; 

} 

@property(nonatomic,retain)UIButton *playPause; 
@property(nonatomic,retain)NSMutableString *audioPath; 
@property(nonatomic,retain)AVAudioPlayer *audioPlayer; 
-(id)initWithTabBar; 
@end 

而且我的執行文件是這樣的

#import "PromoTabOptionHome.h" 
@implementation PromoTabOptionHome 

@synthesize playPause; 
@synthesize audioPath; 
@synthesize audioPlayer; 

-(id) initWithTabBar { 
    if ([self init]) { 
     self.tabBarItem.image = [UIImage imageNamed:@"home.png"]; 

     // set the long name shown in the navigation bar 
     [email protected]"Nav Title"; 
    } 
    return self; 

} 


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib. 
- (void)viewDidLoad { 
    [super viewDidLoad]; 

    playPause = [UIButton buttonWithType:UIButtonTypeCustom]; 
    playPause.frame = CGRectMake(-20,280, 100,100); 
    [playPause setImage:[UIImage imageNamed:@"play.png"] forState:UIControlStateNormal]; 
    [playPause addTarget:self action:@selector(buttonPushed:) 
      forControlEvents:UIControlEventTouchUpInside]; 
    [self.view addSubview:playPause]; 

    playing=NO; 

    NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:audioPath, [[NSBundle mainBundle] resourcePath]]]; 

    NSError *error; 
    audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error]; 
    //audioPlayer.numberOfLoops = -1; 

    if (audioPlayer == nil) 
     NSLog([error description]); 
    else 
     [audioPlayer play]; 
} 

- (void) buttonPushed:(id)sender 
{ 
    NSLog(@"It works!"); 

    switch (playing) { 
     case NO: 
      playing=YES; 
       [playPause setImage:[UIImage imageNamed:@"pause.png"] forState:UIControlStateNormal]; 
      break; 
     case YES: 
      playing=NO; 
       [playPause setImage:[UIImage imageNamed:@"play.png"] forState:UIControlStateNormal]; 
      break; 
     default: 
      break; 
    } 
} 

- (void)didReceiveMemoryWarning { 
    // Releases the view if it doesn't have a superview. 
    [super didReceiveMemoryWarning]; 

    // Release any cached data, images, etc that aren't in use. 
} 

- (void)viewDidUnload { 
    // Release any retained subviews of the main view. 
    // e.g. self.myOutlet = nil; 
} 


- (void)dealloc { 
    [super dealloc]; 
} 


@end 

回答

1

你的AVFoundation框架添加到您的項目?

通過右鍵單擊框架組這樣做,然後單擊添加>現有框架

+0

我試過了,但它不存在於system> libary>框架中。 我想我在尋找一個名爲avfoundation.framework – dubbeat 2010-02-16 15:49:53

+0

東西,我在這裏找到 /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.1.3.sdk/System/Library/Frameworks/UIKit.framework 奇怪的是,X代碼默認情況下不顯示正確的位置? – dubbeat 2010-02-16 16:15:34

+0

如果您在頂部選擇全部,框架應顯示在下拉列表中。 – FelixLam 2010-02-16 16:36:38

0

你可能丟失的AVFoundation.framework項目中的參考。默認情況下不會添加此引用。您需要手動添加AVFoundation.framework

  1. 組和文件 - >展開項目上鏈接二進制文件與庫
  2. 右鍵
  3. 選擇添加
  4. 選擇現有框架 - >一覽彈出現有框架
  5. 選擇AVFoundation.framework
  6. 點擊添加

這應該解決您的問題。這個對我有用。