Re: PlayFile
Re: PlayFile
- Subject: Re: PlayFile
- From: Michael Hanna <email@hidden>
- Date: Mon, 12 Dec 2005 23:11:11 -0800
I see, then can you explain why it's blocking..
Michael
-(IBAction)playFile:(id)sender
{
[self doPlayFile];
}
-(void)doPlayFile
{
AudioFileID audioFile;
const char* inputFile = [fFilePath UTF8String];
FSRef theRef;
XThrowIfError (FSPathMakeRef ((const UInt8 *)inputFile, &theRef,
NULL), "FSPathMakeRef");
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");
printf ("playing file: %s\n", inputFile);
printf ("format: "); fileFormat.Print();
// 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");
// return 0;
}
On 12-Dec-05, at 10:51 AM, William Stewart wrote:
If you are using the PlayFile example, then it should be sufficient
to just return from your button action after calling AUGraphStart -
there's no blocking going on (which is why we have to add the
usleep in the command line version, otherwise the code would just
continue and quit before it actually had the time to play the file)
Bill
On 09/12/2005, at 11:36 PM, Michael Hanna wrote:
I have a
-(IBAction)playFileNow:(id)sender
which is called from the nsbutton. It essentially does what the
main() function does in PlayFile.cpp. Upon clicking, the file
plays but the app becomes completely unresponsive(spinning
pinwheel) until the file has been fully played. I tried removing
the usleep() call but that seemed ineffective. Is this expected
behaviour? How do I make my app responsive to user interaction
while it plays audio?
Michael
On 9-Dec-05, at 12:43 PM, William Stewart wrote:
Cool, I actually made a simple playback cocoa app that wraps the
functions found in PlayFile.cpp.
few things I'd like to know:
- the NSButton stays in the on state. How do I farm-out the
playback task to another thread?
The playback is happening in another thread. Once you start the
graph, playback is taking care of itself:
// start playing
XThrowIfError (AUGraphStart (theGraph), "AUGraphStart");
this is the part where you just return...
we wait in the command line for the file to finish playing
// sleep until the file is finished
usleep ((int)fileDuration * 1000 * 1000);
then we clean up.
// lets clean up
--
mailto:email@hidden
tel: +1 408 974 4056
______________________________________________________________________
____
"Much human ingenuity has gone into finding the ultimate Before.
The current state of knowledge can be summarized thus:
In the beginning, there was nothing, which exploded" - Terry Pratchett
______________________________________________________________________
____
_______________________________________________
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