It's a bit more complicated than that.
What you'll get from 'getting' kAudioUnitProperty_CurrentPlayTime is the -offset- time from when you last set kAudioUnitProperty_ScheduledFileRegion.
If you schedule a new region with that time, you won't resume at the correct place if you pause/resume more than once.
Here is a copy of Doug Wyatt's note on this from 2006, since I no longer have the link:
"To change the play position:
[1] obtain the current play position:
AudioTimeStamp ts;
UInt32 size = sizeof(ts);
AudioUnitGetProperty(mFilePlayerAU,
kAudioUnitProperty_CurrentPlayTime, kAudioUnitScope_Global, 0, &ts,
&size);
Float64 sampleFrame = ts.mSampleTime;
Now you know where playback is, relative to the beginning of the
event timeline that you scheduled. If you
scheduled the beginning of
a file to play at the beginning of the timeline, then the play
position is the same as the position in the file (except in the case
of sample rate conversion, which is another wrinkle.....)
[2] stop:
AudioUnitReset(mFilePlayerAU, kAudioUnitScope_Global, 0);
[3] start again. Here you can specify the starting sample offset in
the file.
For example, to implement pause/resume, you'd obtain the play
position before pausing, and add that to the position in the file
where you last started. That would be the playRegion.mStartFrame when
scheduling the first event when you resume."
Rob
On Jul 18, 2012, at 7:36 PM, Aran Mulholland <
email@hidden> wrote:
> You can't pause the AUFilePlayer. What
you can do is call something like
>
> AudioTimeStamp ts;
> UInt32 size = sizeof(ts);
> AudioUnitGetProperty(filePlayerUnit_,
> kAudioUnitProperty_CurrentPlayTime, kAudioUnitScope_Global, 0, &ts,
> &size);
> Float64 sampleFrame = ts.mSampleTime;
>
> to get the currently playing sample frame, then call
>
> AudioUnitReset(filePlayerUnit_, kAudioUnitScope_Global, 0);
>
> To stop it and if you want to resume playback (from pause), schedule a
> new region with the sample time you had before you called
> AudioUnitReset. Be nice if it had a pause, but not hard to implement
> yourself.