开发者

help!!! when playing a sound animation pauses\slowing

i can't find no solution!!!

animation size 10kb sound size 20kb

here开发者_JAVA技巧 is the code:

    - (void)setupSounds {

        NSString * filePath
        filePath = [[NSBundle mainBundle] pathForResource:@"shake" ofType:@"mp3"];
        soundShuffle = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:filePath ]error:nil];
        sound.volume = 0.4;
        [sound prepareToPlay];
        [sound setDelegate: self];
    }

    - (void) startAnimation {   

[self.Sound setCurrentTime:0.0];
    [self.Sound play];

pos1 = CGPointMake(2.0,7.0);

 kid.center = CGPointMake(kid.center.x+pos1.x,kid.center.y+pos1.y);

    if(kid.center.x > 60 || kid.center.x < 0)
    pos1.x = -pos1.x;
    if(kid.center.y > 236 || kid.center.y < 105)
    pos1.y = -pos1.y;
    }

    - (void) playSound {
        if(self.sound.playing)
        {
            [self.sound stop];
        }
        [self.sound setCurrentTime:0.0];
        [self.sound play];
    }

    - (void)viewDidLoad {
        [self setupSounds];

    }


Every time you call [sound play] it reloads the stream or buffers it or whatever it does to ready it for playing. Basically, AVAudioPlayer is not the right tool for the job -- it is not meant to be used with animation or games or anything of the sort. Check out the "Playing Audio" section of this guide for an alternative:

http://developer.apple.com/iphone/library/referencelibrary/GettingStarted/GS_AudioVideo_iPhone/index.html

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜