views:

190

answers:

3

Hi,

I'm just trying to get a simple mp3 player working. I'm getting an error that I don't really understand.

I have an instance of AVAudioPlayer declared in my h file and I synthesize it in my .m file....

Undefined symbols:
  ".objc_class_name_AVAudioPlayer", referenced from:
      literal-pointer@__OBJC@__cls_refs@AVAudioPlayer in PromoTabOptionHome.o
ld: symbol(s) not found
collect2: ld returned 1 exit status

My h file is defined like this

#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

And my implementation file is like this

#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
        self.navigationItem.title=@"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  A: 

Did you add the AVFoundation framework to your project?

Do so by right clicking the Frameworks group and click Add > Existing Framework

Felix
I tried but it does not exist in system>libary>frameworks.I assume I'm looking for something named avfoundation.framework
dubbeat
I found it here/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.1.3.sdk/System/Library/Frameworks/UIKit.frameworkStrange that x-code doesnt show the correct location by default?
dubbeat
The framework should appear in the drop down list if you select all in the top.
Felix
A: 

You might missing the reference of AVFoundation.framework in your project. By default this reference is not added. You need to add the AVFoundation.framework manually. 1.In Groups and Files-->expand your project 2.Right click on "Link Binaries with Libraries" 3.Select “Add” 4.Select “Existing Framework*s” –>List of existing framework popped up 5.Select “*AVFoundation.framework 6.Click Add

This should resolve your issue. It works for me

Vavani Sarmah
A: 

Wait, i have the same problem, Where is groups and files and then all that stuff i don't know where to find it?!?!?

matt