由于某些原因,我不确定为什么,我的应用程序在OALAudioTrack对象上的fadeTo方法上一直崩溃。
我有三个不同的OALAudioTrack对象,它们在一个数组中,如果给定的值不同,我只需要更改一个OALAudioTrack对象。当值不同时,我需要淡出OALAudioTrack对象,然后淡化新的OALAudioTrack对象并替换数组中的OALAudioTrack对象,但是我不能这样做,因为它在第一次淡出时会一直崩溃(到0.0f) )。当应用程序崩溃时,它总是在同一行上崩溃,该行在OALActionManager.m行#159(NSUInteger index = [targets indexOfObject:action.target];)中,并且错误显示为“Thread 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:)];
}
答案 0 :(得分:1)
崩溃的部分是“action.target”。 “target”是一个弱引用,所以如果你的音轨在动作结束前解除分配,它就会崩溃。
我怀疑在某些时候你的代码要么在其他方法中从self.soundScapes中移除轨道,要么正在进行另一个onFadeComplete调用,在轨道之前生成相同的索引(从而驱逐当前的衰落轨道)淡出完成。