[英]ObjectAL : Crashing on fadeTo:duration:target:selector:
由于某种原因(我不确定为什么),我的应用程序在OALAudioTrack对象的fadeTo方法上不断崩溃。
我在数组中有三个不同的OALAudioTrack对象,如果给定值不同,则只需要更改OALAudioTrack对象即可。 当值不同时,我需要淡出一个OALAudioTrack对象,然后淡入一个新的OALAudioTrack对象,并替换数组中的OALAudioTrack对象,但是我不能这样做,因为这样做在第一次淡出时一直崩溃(到0.0f )。 当应用程序崩溃时,它总是崩溃在同一行上,该行在OALActionManager.m第159号行中(NSUInteger index = [targets indexOfObject:action.target];),并且错误显示“线程1 EXE_BAD_ACCESS”。 在执行淡入淡出之前,我必须做些什么吗,由于我已经看了一天多了,所以我将不胜感激,因此我将不胜感激。 我正在使用的代码如下:
if ([[self.soundScapes objectAtIndex:i] isKindOfClass:[OALAudioTrack class]])
{
[self.tmpSoundScapes removeAllObjects];
[self.tmpSoundScapes addObject:[fnArr objectAtIndex:i]];
[self.tmpSoundScapes addObject:[NSNumber numberWithInt:i]];
OALAudioTrack *currentTrack = [self.soundScapes objectAtIndex:i];
if ([currentTrack playing])
{
NSLog(@"is playing");
[currentTrack stopFade];
//This is where the app crashes
[currentTrack fadeTo:0.0 duration:1.5 target:self selector:@selector(onFadeComplete:)];
}
}
-(void)onFadeComplete:(id)sender
{
NSLog(@"fade complete");
NSString *fn = [self.tmpSoundScapes objectAtIndex:0];
int i = [[self.tmpSoundScapes objectAtIndex:1] intValue];
OALAudioTrack *currentTrack = [self.soundScapes objectAtIndex:i];
[currentTrack stop];
currentTrack = nil;
OALAudioTrack* track = [OALAudioTrack track];
[track preloadFile:fn];
track.autoPreload = YES;
track.numberOfLoops = -1; // Loop forever when playing.
track.gain = 0.0f; // volume
[track play];
[self.soundScapes replaceObjectAtIndex:i withObject:track];
[self.soundScapesFiles replaceObjectAtIndex:i withObject:fn];
int timer;
if (i==1)
timer = 10.0f;
else if (i==2)
timer = 25.0f;
else
timer = 0.5f;
// [self performSelector:@selector(onPlayScoundScape:) withObject:[NSNumber numberWithInt:i] afterDelay:timer];
[track fadeTo:1.0f duration:timer target:self selector:@selector(onPlayScoundScape:)];
}
崩溃的部分是“ action.target”。 “目标”是一个弱引用,因此,如果在操作完成之前取消分配轨迹,它将崩溃。
我怀疑您的代码有时会以某种其他方法从self.soundScapes中删除该轨道,或者正在进行另一次onFadeComplete调用,从而在轨道淡出完成之前生成相同的索引(从而退出当前正在衰减的轨道)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.