views:

33

answers:

2

I have an .aifc file of about 2 minutes that I'm playing using AVAudioPlayer. When I send stop I hear a short 'tick'. When I send play after that I hear the tick again.

I tried setting volume to 0 before sending the play and stop methods, but that didn't work.

The tick is somewhat comparable to the sound you hear when you disconnect your speakerset from its audio source, but really short (and a lot less loud ofcourse).

Any ideas on how to get rid of the tick?

A: 

It's fairly normal for the audio playback mechanism on any platform to produce ticks like this when stopping and restarting the audio. To avoid this problem, instead of abruptly stopping playback by calling stop, you should first ramp down the volume from 1.0 to 0.0 over a short period of time (a few milliseconds is plenty), and then stop or pause. When you resume playback, you would reverse the process by ramping the volume back up from 0.0 to 1.0.

Sorry, I don't know enough iPhonistics to tell you how to do a timer-based operation like this. I am surprised that the AVAudioPlayer library doesn't do this already, but there are other audio APIs out there that I'm sure do.

Update: On second thought, forget it. Ramping the volume down with a timer is a horrible idea and won't work. You'd need a much higher-resolution timer than is possible to avoid a stepping-down effect, which would produce a series of ticks and pops instead of just one.

Use some other API.

MusiGenesis
A: 

Problem solved by setting the volume to 0.0 without calling stop, then calling stop a short time after that. No tick at all!

Rits
That's interesting. AVAudioPlayer must be intelligent enough to ramp the volume down gradually rather than instantaneously.
MusiGenesis
Yes, apparently not. Anyway, thank you for your help!
Rits