2 mp3 sounds at the same time in iphone?

前端 未结 2 881
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-20 04:24

Can we play 2 mp3 sounds on the same time on the iphone?Does iphone support this feature?

2条回答
  •  情深已故
    2020-12-20 05:04

    Yes, but it's annoying as s*** (for the user).

    (sort of(Pseudo-Code)) (I'm too lazy to look up the method names/libraries)

    -(void)playSounds{
        NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init];
        [self playSound1];
        [self playSound2];
        [pool release];
    }
    
    -(void)playSound1{
        NSString *path = [[NSBundle mainBundle] pathForResource:@"file1" 
    ofType:@"m4a"]; AVAudioPlayer* player= [[AVAudioPlayer alloc] initWithContentsOfURL:
    [NSURL fileURLWithPath:path]
    error:NULL]; player.delegate = self; [player play]; } -(void)playSound2{ SString *path = [[NSBundle mainBundle] pathForResource:@"file2"
    ofType:@"m4a"]; AVAudioPlayer* player= [[AVAudioPlayer alloc] initWithContentsOfURL:
    [NSURL fileURLWithPath:path]
    error:NULL]; player.delegate = self; [player play]; }

    Note that this is really quick and dirty. If you want precision, you'll probably have to notify when the players are ready and write a function that fires them at once.

提交回复
热议问题