[英]Problem Playing Audio Iphone
我只是想让一个简单的mp3播放器正常工作。 我遇到了我不太了解的错误。
我在h文件中声明了一个AVAudioPlayer的实例,并在.m文件中对其进行了合成。...
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
我的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
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
您是否将AVFoundation
框架添加到您的项目中?
通过右键单击“框架”组并单击“添加”>“现有框架”来执行此操作
您可能在项目中缺少AVFoundation.framework
的引用。 默认情况下,不添加该引用。 您需要手动添加AVFoundation.framework
。
这样可以解决您的问题。 这个对我有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.