• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How do you pause, stop and reset an AUFilePlayer in IOS5?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How do you pause, stop and reset an AUFilePlayer in IOS5?


  • Subject: Re: How do you pause, stop and reset an AUFilePlayer in IOS5?
  • From: "Beleg Da'Bear" <email@hidden>
  • Date: Tue, 07 May 2013 20:55:44 -0700 (PDT)

Robert,
          Can you expand a little on your comment "except in the case of sample rate conversion, which is another wrinkle"

My pause button is mostly working, however I am finding that when I start the song back up again the audio file starts playing slightly earlier then it should (maybe half or a quarter of a second). The play head is not always wrong, only (roughly) half the time. This makes me suspect that there is some sort of rounding error or conversion error that is causing my stored ts.mSampleTime to be off some of the time.    At first I thought it may be due to the fact that ts.mSampleTime is a Float64 and the ScheduledAudioFileRegion.mStartFrame is a UInt32, but since the mSampleTime never has any value after the decimal point, that should not be an issue. 

Have any thoughts?



From: Robert Martin <email@hidden>
To: Aran Mulholland <email@hidden>
Cc: Beleg Da'Bear <email@hidden>; "email@hidden" <email@hidden>
Sent: Thursday, July 19, 2012 1:13 AM
Subject: Re: How do you pause, stop and reset an AUFilePlayer in IOS5?

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.

 _______________________________________________
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

  • Prev by Date: mediaserverd often crashes with 320 kbps tracks on iOS 6.1.x
  • Next by Date: CalculateIOThreadTimeConstraints on Mountain Lion
  • Previous by thread: mediaserverd often crashes with 320 kbps tracks on iOS 6.1.x
  • Next by thread: CalculateIOThreadTimeConstraints on Mountain Lion
  • Index(es):
    • Date
    • Thread