-1
    -(void)playSound: (NSString*)sound 

{
NSString *path = [[NSBundle mainBundle] pathForResource:sound ofType:@"mp3"];

    AVAudioPlayer* theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
theAudio.delegate = self; 
    [theAudio play];
    [AVAudioPlayer release];
}

一切仍然有效,只是一个恼人的错误可能会导致延迟。

4

1 回答 1

1

确保gameViewController符合AVAudioPlayerDelegate协议:

@interface gameViewController : NSObject <AVAudioPlayerDelegate>
.
.
.
@end

假设那是你班级的名字。

于 2013-01-17T03:17:36.483 回答