• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: AudioQueueDispose vs. AudioQueueStop
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: AudioQueueDispose vs. AudioQueueStop


  • Subject: Re: AudioQueueDispose vs. AudioQueueStop
  • From: Craig Hopson <email@hidden>
  • Date: Mon, 22 Sep 2008 11:46:24 -0600

John,

You are calling:
	AudioQueueStop(myData.audioQueue, false);
And then immediately disposing of the queue (buffers).  This is bad.
Please read the documentation re: AudioQueueStop.

Whether you tell the audio queue to stop immediately or not, you are better off (I think) adding a property listener to the queue for the kAudioQueueProperty_IsRunning property and only dispose of the queue when it signals that it actually has stopped.

-Craig



On Sep 21, 2008, at 9:50 AM, John Zorko wrote:


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


_______________________________________________ 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
  • Follow-Ups:
    • Re: AudioQueueDispose vs. AudioQueueStop
      • From: John Zorko <email@hidden>
References: 
 >AudioQueueDispose vs. AudioQueueStop (From: John Zorko <email@hidden>)

  • Prev by Date: Re: Playing multiple .caf files simultaneously - one queue?
  • Next by Date: Re: AudioQueueDispose vs. AudioQueueStop
  • Previous by thread: AudioQueueDispose vs. AudioQueueStop
  • Next by thread: Re: AudioQueueDispose vs. AudioQueueStop
  • Index(es):
    • Date
    • Thread