AVFoundation iOS 5

给你一囗甜甜゛ 提交于 2019-11-30 17:27:58
sasha_nec

I just have found an answer here.

If your app crashes here, disable All Exceptions in XCode 4 Breakpoints Tab. Maybe it's SDK bug.

Try to make your player a retained property. I experienced the same and because I declared my player locally I think ARC retained as soon as the method in which I declared the player ran out of scope.

Make player a retained property

@property (strong)AVAudioPlayer *player;

Remember to set the delegate (self.player.delegate = self) and use the delegate's methods to clean up:

-(void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)playedSuccessfully {
    self.player = nil;
}
E-Guitar

I found the solution: NSURL instead of NSString:

NSURL *chemin = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/MySound.wav", [[NSBundle mainBundle] resourcePath]]];
NSError *error;
AVAudioPlayer* mySound = [[AVAudioPlayer alloc] initWithContentsOfURL:chemin error:&error];
mySound.delegate = self;
[chemin release];
[mySound Play];

I had the same error, but my code wasn't different from yours. I don't really need anything in the Security framework, but adding that framework to my project fixed this issue.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!