当我运行该程序时,它总是显示程序接收信号SIGABRT。下面是我修改的代码,尤其是AVAudioPlayer。我的代码有什么问题吗?问题是什么?这是断点:int retVal = UIApplicationMain(argc, argv, nil, nil);
-(IBAction) start {
{
self.playBgMusic.enabled = YES;
[self.player play];
}
}
-(IBAction) stop {
{
self.playBgMusic.enabled = NO;
[self.player stop];
}
}
-(void) audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)completed
{
if(completed == YES){
self.playBgMusic.enabled = YES;
}
}
- (void)viewDidLoad
{
NSString *path = [[NSBundle mainBundle] pathForResource:@"music" ofType:@"mp3"];
self.player=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
player.delegate = self;
[player play];
player.numberOfLoops = -1;
[super viewDidLoad];
}
- (void)viewDidUnload
{
[player stop];
[super viewDidUnload];
}
答案 0 :(得分:0)
您可能需要保留self.player
,但您的代码中并不清楚这一点。如果您已将player
(正确)定义为:
@property (nonatomic, retain) AVAudioPlayer *player;
...然后你有一个不同的问题。