AudioQueueDispose vs. AudioQueueStop
AudioQueueDispose vs. AudioQueueStop
- Subject: AudioQueueDispose vs. AudioQueueStop
- From: John Zorko <email@hidden>
- Date: Sun, 21 Sep 2008 08:50:26 -0700
Hello, all ...
So i'm working on this streaming application, and it streams and plays
the first item in my list fine ... but when I try to start playing
another item (hence stopping the first), things get wonky. I'm
apparently not stopping the audio queue correctly. The relevant parts
of my code follow (based heavily on AudioFileStreamExample), but I
don't know the difference between AudioQueueDispose and
AudioQueueStop. How does one stop an audio queue quickly (_can_ an
audio queue be stopped quickly?) so another queue can be started?
- (void)playStream:(Song *)streamToPlay
{
keepRunningThread = 0; // tell current thread to stop
while(myData.playing == YES) // wait for it to stop
{
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode
beforeDate:nil];
}
// ... and start a new one with the new stream to play
NSLog(@"starting thread to play mp3 stream %s", [streamToPlay.mp3
UTF8String]);
[NSThread detachNewThreadSelector:@selector(connectAndPlayStream:)
toTarget:self withObject:streamToPlay];
}
- (void)connectAndPlayStream:(Song *)streamToPlay
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
myData.playing = YES;
keepRunningThread = 1;
// initialize a mutex and condition so that we can block on buffers
in use.
pthread_mutex_init(&myData.mutex, NULL);
pthread_cond_init(&myData.cond, NULL);
OSStatus err = AudioFileStreamOpen(&myData, MyPropertyListenerProc,
MyPacketsProc,
kAudioFileAAC_ADTSType, &myData.audioFileStream);
if (err)
{
NSLog(@"AudioFileOStreamOpen error %d", err);
}
NSString *url = @"http://he3.magnatune.com/all/";
url = [url stringByAppendingString:streamToPlay.mp3];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL
URLWithString:[url
stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]]
cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
NSURLConnection *connection = [[NSURLConnection alloc]
initWithRequest:request delegate:self];
if (connection)
{
receivedData = [[NSMutableData data] retain];
}
else
{
NSLog(@"can't connect to server");
}
while (keepRunningThread)
{
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode
beforeDate:nil];
// if we've been told to stop, stop ...
if (keepRunningThread == 0)
{
[connection cancel];
AudioQueueStop(myData.audioQueue, false);
AudioFileStreamClose(myData.audioFileStream);
AudioQueueDispose(myData.audioQueue, false);
}
}
myData.playing = NO;
pthread_cond_destroy(&myData.cond);
pthread_mutex_destroy(&myData.mutex);
[pool release];
exit;
}
Regards,
John
Falling You - exploring the beauty of voice and sound
http://www.fallingyou.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden