出于某种原因,我不确定为什么,我的应用程序在 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:)];
}