[英]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.