views:

87

answers:

3

when playing a sound the animation freeze\slowing problem.

sound size 20kb mp3.

animation size 5kb png.

also happens in other animation functions.

basically whenever i play a sound the animation slowing down or pauses, what to do ???

code:

- (void) startAnimation { 

 [UIView beginAnimations:nil context:nil];
 [UIView setAnimationDuration:0.8];
 CGPoint destination = CGPointMake(152,20);
 pink.center = destination;
 [UIView commitAnimations];
 [soundPink play];    
}


- (void) initSoundResources {

 soundPink = [[APlayer alloc] initWithFile:@"ballShuffle" type:@"mp3"];
 soundPink = 0.4;
 }
A: 

Try the following hack:

[soundPink performSelector:@selector(play) withObject:nil afterDelay:0.001];
Frank Schmitt
AVAudioPlayer is already asynchronous, this may not help, I've found that most of the audio pauses before playing are during the prepareToPlay stage which you can call manually.
NWCoder
but the animation pauses not the audio.i post my init function (maybe something is wrong there)
nil
A: 

How large is the sound file? It's possible you're trying to load too large a sound into memory, which is slowing things down. Remember, the iPhone is not a desktop computer, so you have to consider the size of media files more carefully.

Joshua Nozzi
the biggest one is 400kb, is that too big?
nil
A: 

The answer may be to add a prepareToPlay can (which the play does explicitly) before the animation block so there is no stutter.

- (void) startAnimation {   
    [soundPink prepareToPlay];           
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.8];
    CGPoint destination = CGPointMake(152,20);
    pink.center = destination;
    [UIView commitAnimations];
    [soundPink play];           
}
NWCoder
noop. didn't help.
nil