救命!!!播放声音动画时暂停\放慢速度

时间:2009-12-10 21:24:13

标签: iphone objective-c

我找不到解决方案!!!

动画大小10kb 声音大小20kb

这是代码:

    - (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];

    }

1 个答案:

答案 0 :(得分:1)

每当你调用[声音播放]时,它会重新加载流或缓冲它或者它做的任何事情以准备播放。基本上,AVAudioPlayer不适合这项工作 - 它不适用于动画或游戏或任何类型的东西。请查看本指南的“播放音频”部分以获取替代方法:

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