Umair_uas
Umair_uas

Reputation: 673

AVAudioPlayer give lazy feedback when preesing sound button

I am using AVAudioPlayer, When i pressed button, the sound is playing but its lazy(or giving me late feedback), How can i play sound with rapid feedback..Thanks

Upvotes: 0

Views: 174

Answers (2)

Anish
Anish

Reputation: 2927

Try Like this...

In .h

AVAudioPlayer *playerBG

In .m

AVAudioPlayer *pp = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Ting" ofType:@"wav"]] error:nil];
self.playerBG = pp;
[pp prepareToPlay];
[pp release];

Upvotes: 1

Tom Jefferys
Tom Jefferys

Reputation: 13310

Are you calling prepareToPlay before trying to play the sound? As the method suggests this does all the preparation, meaning subsequent calls to play should be very quick.

If you need even lower latency, you may need to use AVAudioQueues though.

Upvotes: 1

Related Questions