AVAudioPlayer sometimes starts skipping -- looping the last 1/4 second of the sound

Discussion in 'iOS Programming' started by 99miles, Jul 12, 2009.

  1. 99miles macrumors member

    Oct 10, 2008
    I'm using AVAudioPlayer to play sounds (SDK 2.2.1). Below if the code I'm using that's in a method that is called when I touch the screen. I stop any sounds that's already playing to play a new one if the touch occurs while another sounds is already playing.

    The problem is that every 3-5 times that I start a sound, the sound completes and then starts looping the last little bit of the sound. It sounds like a cd skipping. I've spent 3 hours trying different things, and Googling brings up nothing. Any ideas? Thanks in advance!

    int soundNum			= arc4random() % [soundsArray count];
    AVAudioPlayer *sound	= [soundsArray objectAtIndex:soundNum];
    [currentSound stop];
    currentSound = nil;
    currentSound = sound;
    [currentSound setCurrentTime:0.0];
    [currentSound play];
  2. yjchun macrumors newbie

    Aug 3, 2009
    I'm having the same problem

    I'm having the same problem.
    iPod touch, SDK 2.2.1. Exactly same problem.
    I used mp3 sample files at first time and it started skipping (looping end of the sound)
    occasionally. maybe once out of a dozen of times. and then converted all media to aac/caf format using afconvert. This time the problem happens once in twice. Code is fairly simple and straightforward, no much room for error.
    It loads audio file one at a time and play it. when it is finished (or error occurs), play next audio file.

    Please let me know if a solution is found.
  3. 99miles thread starter macrumors member

    Oct 10, 2008
    The problem went away for me when I used wav files instead of caf. Really irritating. Good luck!
  4. yjchun macrumors newbie

    Aug 3, 2009
    Thank you for the info.
    In my case, using wav is not really an option. size of audio files are already too much.

    I tried to convert original wave to mp3 and caf and m4a using aac codec. using caf, almost 100% of the looping problem but with m4a the chances were a little lower. Tried to change channels and bitrates but no difference.

    So media container format matters. That's all I figured out so far..sigh.
    SDK 2.2 is causing me too much trouble.
    I will update when i find anything new.

Share This Page