У меня есть класс, который я называю использовать AVAudioPlayer
и все работает нормально, и денди, когда речь идет о воспроизведении аудио, но когда -audioPlayerDidFinishPlaying:
называется моя NSLog()
команды говорит, что игрок освобождается; проблема в том, что приложение выйдет из строя через несколько секунд. Я должен отметить, что audioPlayer
является ivar в этом классе. Вот код:EXC_BAD_ACCESS после audioPlayerDidFinishPlaying: называется
-(id) initWithFileName:(NSString *)sndFileName
{
[super init];
sndFileToPlay = [[NSString alloc] initWithString:sndFileName];
return self;
}
-(void)dealloc {
[audioPlayer release];
self.audioPlayer.delegate = nil;
self.audioPlayer = nil;
[super dealloc];
}
-(void)play
{
[self playSound:sndFileToPlay];
}
-(void)playSound:(NSString *)fileName
{
NSString *fname, *ext;
NSRange range = [fileName rangeOfString:@"."];
int location = range.location;
if(location > 0)
{
fname = [fileName substringWithRange:NSMakeRange(0, location)];
ext = [fileName substringFromIndex:location+1];
[self playSound:fname :ext];
}
}
-
-(void)playSound:(NSString *)fileName :(NSString *)fileExt
{
NSBundle *mainBundle = [NSBundle mainBundle];
NSURL *fileURL = [NSURL fileURLWithPath:
[mainBundle pathForResource:fileName ofType:fileExt] isDirectory:NO];
if (fileURL != nil)
{
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL: fileURL
error: nil];
[fileURL release];
[audioPlayer setDelegate:self];
[audioPlayer play];
}
}
- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player
successfully:(BOOL)flag
{
NSLog(@"Releasing");
[audioPlayer release];
}
Измените свой вопрос и исправьте форматирование. Благодарю. – DarkDust