Re: Callback when AUFilePlayer is finished?
Re: Callback when AUFilePlayer is finished?
- Subject: Re: Callback when AUFilePlayer is finished?
- From: Kariem Morsy <email@hidden>
- Date: Tue, 17 Oct 2006 21:53:01 +0200
>> Anyone know an alternative to polling the current play time?
or simply regstier a completion callback when scheduling the audio file region before playback:
rgn.mCompletionProc= myCallbackFunction;
rgn.mCompletionProcUserData= someUserData; // optional
where myCallbackFunction is defined as follows:
void myCallBackFunction(void *userData, ScheduledAudioFileRegion *fileRegion, OSStatus result){
// do something
}
Note, however, that this function is not only called when rgn.mFramesToPlay frames were played,
which in your case is probably the whole file, but also everytime you reset the file player, for
example when you want to change the playback position. so in that case make sure to check the
data that's passed to the callback to find that out.
as for the metering, adding a mixer unit should not require a lot of work.
just connect a stereo or matrix mixer in between the fileplayer and the output unit, and query the
mixer unit for its averagePower parameter.
Karim
<br />Message: 4
<br />Date: Tue, 17 Oct 2006 06:21:28 -0700
<br />From: David Duncan
<br />Subject: Re: Callback when AUFilePlayer is finished?
<br />To: "M. Uli Kusterer"
<br />Cc: email@hidden
<br />Message-ID: <email@hidden>
<br />Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed
<br />
<br />On Oct 17, 2006, at 04:32 AM, M. Uli Kusterer wrote:
<br />
<br />> I've managed to find the FilePlayer sample code I can use to
<br />> achieve nice playing of raw sound data. Now, I have a few things
<br />> even repeated Googles couldn't solve for me, so I hope someone here
<br />> can help me:
<br />>
<br />> Is there any way I can get an AUFilePlayer (or the output unit in
<br />> my graph, or whatever) to notify me when it's finished playing
<br />> sound? I've found that the current play time will be -1 when it's
<br />> finished playing, so I could poll, but certainly there's a callback
<br />> somewhere I can register for to get that information?
<br />>
<br />> Most code on the web assumes I'm feeding data into the Audio Units
<br />> myself, so I'll know when I'm at the end, but of course when I go
<br />> through FilePlayer that isn't the case.
<br />>
<br />> Anyone know an alternative to polling the current play time?
<br />
<br />Checkout the Audio Unit Events APIs. They are discussed in TechNote
<br />2104 here:
<br />
<br />The basic jist of it is that you setup an audio event callback on
<br />your file player to watch the kAudioUnitProperty_CurrentPlayTime
<br />property on your file player, and it will notify you as the property
<br />changes with time.
<br />
<br />If you just care about knowing when it ends, you can set the
<br />Notification Interval and Value Change Granularity exceptionally high
<br />(on the order of the length of the file). If you have some UI to
<br />update as well, I would probably set both to be half a second. Either
<br />way it should reduce the amount of time you spend asking about the
<br />property value.
<br />--
<br />Reality is what, when you stop believing in it, doesn't go away.
<br />Failure is not an option. It is a privilege reserved for those who try.
<br />
<br />David Duncan
<br />
_______________________________________________
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