开发者

problem - when playing a sound the animation freeze\slowing

开发者 https://www.devze.com 2022-12-14 02:41 出处:网络
when playing a sound the animation freeze\\slowingproblem. sound size 20kb mp3. animation size 5kb png.

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 = [[APlay开发者_如何学Goer alloc] initWithFile:@"ballShuffle" type:@"mp3"];
 soundPink = 0.4;
 }


Try the following hack:

[soundPink performSelector:@selector(play) withObject:nil afterDelay:0.001];


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.


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];           
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号