Hi, I am working on an audio streaming iPhone application.
When user taps the play button, i starts the internal thread to receive the stream audio and i have scheduled the stream source with NSRunLoop like below [_stream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; When ever user taps the stop button, i want to stop the playback and terminate the secondary thread. when i do so, playback stopped, But the thread is not terminating as it stuck in the Runloop's runMode method. it never returns. - (BOOL)shouldStopAudioPlayback { if (_playerState == kStreamPlayerEngine_Stopped || _playerState == kStreamPlayerEngine_ConnectionClosed || _playerState == kStreamPlayerEngine_ConverterFailure) { printf("shouldStopPlyback = YES\n"); return YES; } printf("shouldStopPlyback = FALSE\n"); return NO; } - (void)startInternalThread { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; [self initializeAudioPlayBuffer]; [self openReadStream]; BOOL isRunning = YES; do { printf("before runloop\n"); isRunning = [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.25]]; printf("after runloop\n"); } while (isRunning && ![self shouldStopAudioPlayback]); [self cleanupAudioPlayBuffer]; [_internalThread release]; _internalThread = nil; [pool release]; NSLog(@"Exiting from Thread"); } - (void)play { if ([NSThread isMainThread]) { _internalThread = [[NSThread alloc] initWithTarget:self selector:@selector (startInternalThread) object:nil]; [_internalThread setName:@"StreamPlayer Thread"]; [_internalThread start]; } } - (void)stop { OSStatus error; error = AUGraphStop(mGraph); if (error) { [self printErrorMessage:@"AUGraphStop failure" withStatus:error]; } self.playerState = kStreamPlayerEngine_Stopped; printf("stopped AUGraph\n"); return; } Trace log ============= before runloop after runloop shouldStopPlyback = FALSE before runloop after runloop shouldStopPlyback = FALSE before runloop after runloop shouldStopPlyback = FALSE before runloop after runloop shouldStopPlyback = FALSE before runloop stopped AUGraph I am not sure what is the issue here. Please any one guide me what is the wrong with above code in handling the RunLoop. Thanks Sasikumar JP _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com