Running thread prevents full playback of audio on iPhone
I've created an app using the SpeakHere example. The program takes the vocal input, run some effects on it and then writes it to a file for playback.
I've created a thread that runs the audio processing code while showing a little animation. Everything works fine except when the thread is finished and I hit playback, it only plays for a few seconds and then it stops. The odd thing about this is that there is no other change or error being produced. I've downloaded the audio off the device to my machine and it is all there, so it is not as if the recording is shorter.
[NSThread detachNewThreadSelector:@selector (run_thread)
toTarget:self
withObject:nil];
And then the method:
-(void)run_thread
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
printf("Running Thread...\n");
recordFilePath = runAllAudioRoutines();
NSString *print_recordFilePath= (NSString *)recordFilePath;
NSLog(@"RECORD FILE PATH ----> %@", print_recordFilePath);
player->CreateQueueForFile(recordFilePath);
bars_mixing_rap = false;
//开发者_JS百科 Set the button's state back to "record"
btn_record.title = @"Record";
btn_record.enabled = YES;
btn_play.enabled = YES;
LOADING = FALSE;
[pool drain];
}
Any ideas?
Is the code thread safe ? It's not clear what runAllAudioRoutines() does or what btn_record and btn_play are, but if btn_record was, say, an instance of NSButton you cant set it's title or enabled state from your background thread.
精彩评论