应用与AVAudioPlayer播放声音时冻结
-
23-09-2019 - |
题
我将某个应用学龄前儿童与几个小游戏。其中之一包括寻找“什么是错的”的图片。例如,如果他们按小子打在大街上,一个pling声音,孩子移出街道和标签更新为“1/5发现错误”。如果他们找到他们,他们移动到新的业务差错新的视图控制器。
一切工作就好了......大部分时间。但在每一次,而应用程序播放pling,然后冻结。我认为它与声音(与AVAudioplayer)的实际播放的事,因为如果我评论说出来,好像每次的功能。
当发现错误时调用的功能是这样的:
-(void)fantKnapp{
NSLog(@"fant en knapp");
int ant =[self.antall intValue];
ant++;
NSLog(@"antall %i",ant);
self.antall=[NSNumber numberWithInt:ant];
self.poeng.text=[NSString stringWithFormat: @"%i/5 funnet",ant];
if(ant==5){
NSLog(@"Du klarte alle!");
klartAlleView.hidden=NO;
spillIgjen.hidden=NO;
nestebrettKnapp.hidden=NO;
navtestAppDelegate *appDelegate=(navtestAppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate spillLyd:@"du_klarte_alle"];
}
else{
navtestAppDelegate *appDelegate=(navtestAppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate spillLyd:@"cling_1"];
}
}
此代码的发现“antall”,发现的错误(点)的当前数目。如果已经发现的所有错误一定的播放声音(这一个始终有效)。如果没有其他的声音播放。这是通过在文件的appdelegate调用函数进行。
-(void)spillLyd:(NSString*) filnavn{
NSString *audioFilePath=[[NSBundle mainBundle] pathForResource:filnavn ofType:@"aif"];
NSURL *audioFileURL=[NSURL fileURLWithPath:audioFilePath];
self.lydspiller=[[[AVAudioPlayer alloc] initWithContentsOfURL:audioFileURL error:nil] autorelease];
[self.lydspiller prepareToPlay];
[self.lydspiller play];
NSLog(@"spiller lyden");
}
这只是正常的49/50例,但每过一段时间它does not。有趣的是,声音确实发挥,但应用程序冻结,标签不更新(self.poeng.text = ...)。但所有的NSLog意见显示,包括点的新号码。我希望这样的事情发生之前,播放声音...
这是与AVAudioplayer的问题吗?有没有人有类似的经历?谁能帮我在这一个?我感谢任何帮助或建议...
(约在挪威抱歉。这可能犯规使它变得更容易帮我...)
没有正确的解决方案
其他提示
您可能需要实现AVAudioPlayerDelegate
方法,让你可以尝试从播放器捕获错误。如果委托报告,玩家成功完成,即使该应用程序冻结,那么错误很可能不涉及到球员。
我对你的感觉。很少调试任务都超过追查明确,但高度间歇性的错误令人沮丧。
不隶属于 StackOverflow