objective c - How can I fade out an AVAudioPlayer on a background thread? -
i have audio file needs fade out while user scrolling uiscrollview. however, performselector:withobject:afterdelay:
method blocked until user has stopped scrolling. have tried create code perform fadeout on thread:
- (void)fadeout { [nsthread detachnewthreadselector:@selector(fadeoutinbackground:) totarget:self withobject:self.audioplayer]; } - (void)fadeoutinbackground:(avaudioplayer *)aplayer { nsautoreleasepool *mypool = [[nsautoreleasepool alloc] init]; [self performselector:@selector(fadevolumedown:) withobject:aplayer afterdelay:0.1]; [mypool release]; } - (void)fadevolumedown:(avaudioplayer *)aplayer { aplayer.volume = aplayer.volume - 0.1; if (aplayer.volume < 0.1) { [aplayer stop]; } else { [self performselector:@selector(fadevolumedown:) withobject:aplayer afterdelay:0.1]; } }
it gets far performselector, no further because guess it's trying perform on thread has no access to. can't change performselector:onthread:withobject:waituntildone:
because there no delay option.
any ideas? why have made hard fade out sound? moan
thanks!
i resolved similar issue scheduling selector in different run loop mode default one. way not interfering scrolling events. using nsrunloopcommonmodes
worked me:
[self performselector:@selector(fadevolumedown:) withobject:aplayer afterdelay:0.1 inmodes:[nsarray arraywithobject: nsrunloopcommonmodes]];
Comments
Post a Comment