J'essaie juste de faire fonctionner un simple lecteur mp3. Je reçois une erreur que je ne comprends pas vraiment.Problème de lecture audio Iphone
J'ai une instance de AVAudioPlayer déclaré dans mon dossier h et je synthétisent dans mon fichier .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
Mon fichier h est défini comme celui-ci
#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
Et mon dossier de mise en œuvre est comme ce
#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
J'ai essayé mais il n'existe pas dans system> libary> frameworks. Je suppose que je suis à la recherche de quelque chose nommé avfoundation.framework – dubbeat
Je l'ai trouvé ici /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.1.3.sdk/System/Library/Frameworks/UIKit.framework Étrange que x-code ne montre pas l'emplacement correct par défaut? – dubbeat
Le cadre devrait apparaître dans la liste déroulante si vous sélectionnez tout en haut. – FelixLam