0

我在scrollviewusing中播放了这 2 种声音AVAudioPlayer

问题是这sleep()会造成延迟,我需要一种替代方法,以便在没有睡眠功能的情况下更轻松地一个接一个地播放两种声音。

PS:文件名由用户所在的scrollView中的页面给出。

   if( nextPage!=6 )  {
    [scrMain scrollRectToVisible:CGRectMake(0, nextPage*250, scrMain.frame.size.width, scrMain.frame.size.height) animated:YES];
    pgCtr.currentPage=nextPage;


    NSString *path;
    NSError *error;
    path = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"pas%02i",nextPage+1] ofType:@"m4a"];
    if ([[NSFileManager defaultManager] fileExistsAtPath:path])
    {
        player = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:&error];
        player.volume = 0.5f;
        [player prepareToPlay];
        [player setNumberOfLoops:0];
        [player play];
    }
    sleep(1);

    NSString *path2;
    NSError *error2;
    path2 = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"passun%02i",nextPage+1] ofType:@"m4a"];
    if ([[NSFileManager defaultManager] fileExistsAtPath:path2])
    {
        player = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path2] error:&error2];
        player.volume = 0.5f;
        [player prepareToPlay];
        [player setNumberOfLoops:0];
        [player play];
    }

我怎样才能做到这一点?

4

0 回答 0