Re: Detecting file completion of AUAudioFilePlayer playback
Re: Detecting file completion of AUAudioFilePlayer playback
- Subject: Re: Detecting file completion of AUAudioFilePlayer playback
- From: Doug Wyatt <email@hidden>
- Date: Tue, 1 Dec 2009 18:55:22 -0800
On Dec 1, 2009, at 0:59 , Björn Kempen wrote:
> Hi, I'm working on an app which uses an AUAudioFilePlayer audio unit
> and I just can't seem to find a way to get a callback once the file
> has finished playing.
>
> Looking through the docs in AudioUnitProperties.h revealed something a
> bit weird.
>
> The docs first claim "The unit is a subclass of AUScheduledSoundPlayer
> and inherits all of its "behavior.".
> However, in the Completion Callbacks section, it seems like
> mCompletionProc does something completely different.
I guess that could be described as an "override" to the inherited behavior :-/
> In other words, it seems like the callback is called when the
> scheduled sound of an AUScheduledSoundPlayer has finished playing, but
> it will be called prior to that (since the scheduling will be
> completed before the playback) for AUAudioFilePlayer.
>
> My usage of mCompletionProc on an AUAudioFilePlayer confirms this,
> which is sortof bad since I'd rather not have to resort to polling the
> player to find out when the sound has finished playing.
>
> Anyone has any ideas how to detect when playback has finished?
As a general approach, you can keep track of how many sample frames you schedule for playback (plus any gaps between regions), and the device sample time at which the AU starts. When the current playback sample time (on the device timeline) reaches start_time + frames_scheduled, or if it simply reaches frames_scheduled on the playback timeline, then you've reached the end.
Doug
_______________________________________________
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