Re: Callback when AUFilePlayer is finished?
Re: Callback when AUFilePlayer is finished?
- Subject: Re: Callback when AUFilePlayer is finished?
- From: "tahome izwah" <email@hidden>
- Date: Wed, 18 Oct 2006 14:53:01 +0200
I'm not sure if it helps but I am using the following code in my own
program to play a file. Works perfectly and you know when you're done
playing it. This is derived from some Apple example code that is in
the CoreAudio examples directory. This means that you need some of the
AudioFilePlayer support files in your project as well.
// -----------------------------------------------------------------------------------------------------------------------------
//
// play sound in file pointed to by theRef
//
// -----------------------------------------------------------------------------------------------------------------------------
//
void PlaySound(FSRef theRef)
{
AudioFileID audioFile;
XThrowIfError (AudioFileOpen (&theRef, fsRdPerm, 0,
&audioFile), "AudioFileOpen");
// get the number of channels of the file
CAStreamBasicDescription fileFormat;
UInt32 propsize = sizeof(CAStreamBasicDescription);
XThrowIfError (AudioFileGetProperty(audioFile,
kAudioFilePropertyDataFormat, &propsize, &fileFormat),
"AudioFileGetProperty");
// lets set up our playing state now
AUGraph theGraph;
CAAudioUnit fileAU;
// this makes the graph, the file AU and sets it all up for playing
MakeSimpleGraph (theGraph, fileAU, fileFormat, audioFile);
// now we load the file contents up for playback before we start playing
// this has to be done the AU is initialized and anytime it is
reset or uninitialized
Float64 fileDuration = PrepareFileAU (fileAU, fileFormat, audioFile);
printf ("file duration: %f secs\n", fileDuration);
// start playing
XThrowIfError (AUGraphStart (theGraph), "AUGraphStart");
// sleep until the file is finished
usleep ((int)fileDuration * 1000 * 1000);
// lets clean up
XThrowIfError (AUGraphStop (theGraph), "AUGraphStop");
XThrowIfError (AUGraphUninitialize (theGraph), "AUGraphUninitialize");
XThrowIfError (AudioFileClose (audioFile), "AudioFileClose");
XThrowIfError (AUGraphClose (theGraph), "AUGraphClose");
printf ("PlaySound has finished\n");
}
// -----------------------------------------------------------------------------------------------------------------------------
Does that help?
Cheers,
--th
_______________________________________________
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