Re: How do you pause, stop and reset an AUFilePlayer in IOS5?
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: Aran Mulholland <email@hidden>
- Date: Tue, 31 Jul 2012 09:25:43 +1000
Does restarting the AUGraph mean the app is unresponsive when you hit play?
On Tue, Jul 31, 2012 at 7:04 AM, Beleg Da'Bear <email@hidden> wrote:
> I figured it out. In case you ever run into the same problem, here was my
> solution
> 1. On startup, I initialize the AUGraph with an array of file player
> audio units. I set the play head of each track in the file player audio unit
> array to zero.
> 2. On “pause” , first I stop the AuGraph. Then I loop through the array
> of file player audio units and capture the current playhead position. Each
> time the pause button is pressed, I make sure I add the new current
> playhead position to the old playhead position to get its true position.
> 3. When the user hits play, I re initialize the AuGraph just as if I
> was coming to the page for the very first time, only I set the playhead to
> the number I stored when the user hit “pause” instead of telling it to play
> at the start of the file.
> 4. If the user clicks stop, I set the stored playhead position to zero
> and then stop the AuGraph.
>
> This may not be the most efficient way to do things, I still think that
> using kAudioUnitProperty_ScheduleStartTimeStamp to start the multiple file
> player audio units in a few seconds in the future would work better, but
> since I could not get that to work and this method is working for me, I will
> take it. My only issue at this point is that when I pause and then play
> again, it starts the playhead a second or a second and a half earlier then
> when I expect it too. But I am sure I will be able to figure out this minor
> bug when I get back to this project over the weekend.
> Aran,
> Robert,
> Thanks for your pointers as well the link to Doug Wyatt’s code.
> This was helpful in getting me on the right path
>
> From: Beleg Da'Bear <email@hidden>
> To: Aran Mulholland <email@hidden>
> Cc: "email@hidden" <email@hidden>
> Sent: Thursday, July 26, 2012 11:51 AM
>
> Subject: Re: How do you pause, stop and reset an AUFilePlayer in IOS5?
>
> Yes. My thinking is that, since all my tracks are the same size, I can
> assign the playback head to the same number that i get from the first track.
> (my tests have indicated this will work). However there is still the problem
> scheduling when the playback should begin. Typically I would want the File
> Player to start right away. I can accomplish this by setting mSampleTime =
> -1. However since this is all happening in a loop, I want the playback to
> begin after a slight delay, perhaps 1 second from the current time. Does
> anyone know what I would need to set mSampleTime to in this case?
> Code:
>
> // tell the file player AU when to start playing (-1 sample time means next
> render cycle)
> AudioTimeStamp startTime;
> memset (&startTime, 0, sizeof(startTime));
> startTime.mFlags = kAudioTimeStampSampleTimeValid;
> startTime.mSampleTime = -1;
> AudioUnitSetProperty(fileUnitArray[mycount],
> kAudioUnitProperty_ScheduleStartTimeStamp, kAudioUnitScope_Global, 0,
> &startTime, sizeof(startTime));
>
>
>
>
> From: Aran Mulholland <email@hidden>
> To: Beleg Da'Bear <email@hidden>
> Cc: Robert Martin <email@hidden>;
> "email@hidden" <email@hidden>
> Sent: Tuesday, July 24, 2012 7:43 PM
> Subject: Re: How do you pause, stop and reset an AUFilePlayer in IOS5?
>
> If you knew the host time that you started the region at you could get
> the host time when you hit pause and work this out without asking the
> API.
>
> On Tue, Jul 24, 2012 at 11:47 PM, Beleg Da'Bear <email@hidden>
> wrote:
>> Thanks. after I took out the bits stopping the AuGraph as well as adding
>> in
>> a step I skipped (I forgot to do kAudioUnitProperty_ScheduleFilePrime) I
>> get
>> the pause play behavior that I am looking for, however as I expected
>> pausing
>> and then playing again causes the 8 tracks to get slightly out of synch. I
>> suspect that this is happening because I have a for loop that cycles
>> through
>> my FilePlayer Audio Unit array to capture the current sample time and this
>> must be introducing a slight delay for the time it takes to loop through
>> all
>> 8 tracks. Do you know of a way to get the sample time for all 8 files at
>> the same time?
>>
>> From: Aran Mulholland <email@hidden>
>> To: Beleg Da'Bear <email@hidden>
>> Cc: Robert Martin <email@hidden>;
>> "email@hidden" <email@hidden>
>> Sent: Monday, July 23, 2012 8:15 PM
>>
>> Subject: Re: How do you pause, stop and reset an AUFilePlayer in IOS5?
>>
>> Don't stop the AUGraph. The time it takes to start is too long. the
>> AUFilePlayer will just fill the buffer with 0's if it is not playing
>> and probably sets the "norender" flag as well. This way when you start
>> the player again it start playing straight away.
>>
>>
>> On Tue, Jul 24, 2012 at 4:52 AM, Beleg Da'Bear <email@hidden>
>> wrote:
>>> Upon closer inspection it looks like I am not always getting the value I
>>> should for the sample frame.
>>> When I do this the first time:
>>> AudioTimeStamp ts;
>>> UInt32 size = sizeof(ts);
>>> AudioUnitGetProperty(myArrayOfFileUnits[count],
>>> kAudioUnitProperty_CurrentPlayTime, kAudioUnitScope_Global, 0, &ts,
>>> &size);
>>> I get the number I would expect. the second time I hit pause
>>> ts.mSampleTime
>>> = -1.
>>> Any thoughts on why this would be the case?
>>> As a follow up question, Should I be worried about the time it takes to
>>> looping through an array of FilePlayer units to get the sampleTime for
>>> each
>>> unit? In other words is it possible that I will capture the current play
>>> head for each track at a slightly different time, thus making them
>>> misaligned when I hit play again? If this is the case, how would I work
>>> around that problem?
>>>
>>>
>>> From: Beleg Da'Bear <email@hidden>
>>> To: Robert Martin <email@hidden>; Aran Mulholland
>>> <email@hidden>
>>> Cc: "email@hidden" <email@hidden>
>>> Sent: Monday, July 23, 2012 2:01 PM
>>>
>>> Subject: Re: How do you pause, stop and reset an AUFilePlayer in IOS5?
>>>
>>> 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
>
>
_______________________________________________
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
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>) |
| >Re: 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: "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: "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: "Beleg Da'Bear" <email@hidden>) |
| >Re: How do you pause, stop and reset an AUFilePlayer in IOS5? (From: "Beleg Da'Bear" <email@hidden>) |