• 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: Mon, 23 Jul 2012 11:01:56 -0700 (PDT)

Thanks. I tried this method out this weekend and I am having trouble making it work. Should I be stopping and starting the AudioGraph each time?
Here is my aproch (My code complicates things a little because I am trying to play/pause 8 files at the same time.)
If the user presses the play button.
1. Loop through the 8 FilePlayer audio units scheduling the start frame of each unit to 0;
2. call AUGraphStart  
If the user presses the pause button.
1. Loop through the 8 FilePlayer audio units and get the sample frame of the curently playing tracks.
2. Store this number for later (if the user hits pause a second time add the new number to the old number, i.e. SampleFrame=SampleFrame + ts.mSampleTime;)
3. call AudioUnitReset
4. Stop the AuGraph
When the user unpauses the pause button
1. Loop through the 8 FilePlayer audio units and set the startFrame to the number we stored
2. call AUGraphStart
When the user hits stop
1. stop the AUGRAPH
2. Reset the sampleFrame to zero for all FilePlayer audio units
The behavior I am seeing is that the music plays fine the first time that the play button is pressed. Pressing pause or stop stores the value I expect to see in the startFrame, however pressing play again does nothing. I hear nothing. The odd thing is that If I press pause and then play realy really quickly, it works as I want it to, however I think this is because I am hitting play because the AUGraph had a chance to really stop. but I am not sure. Any ideas what I am missing?
 
 
Thanks.
 

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

  • Follow-Ups:
    • Re: How do you pause, stop and reset an AUFilePlayer in IOS5?
      • From: "Beleg Da'Bear" <email@hidden>
References: 
 >How do you pause, stop and reset an AUFilePlayer in IOS5? (From: "Beleg Da'Bear" <email@hidden>)
 >Re: How do you pause, stop and reset an AUFilePlayer in IOS5? (From: Aran Mulholland <email@hidden>)
 >Re: How do you pause, stop and reset an AUFilePlayer in IOS5? (From: Robert Martin <email@hidden>)

  • Prev by Date: MIDIClientCreate returns kMIDIServerStartErr -10839
  • Next by Date: Re: How do you pause, stop and reset an AUFilePlayer in IOS5?
  • Previous by thread: Re: How do you pause, stop and reset an AUFilePlayer in IOS5?
  • Next by thread: Re: How do you pause, stop and reset an AUFilePlayer in IOS5?
  • Index(es):
    • Date
    • Thread