2011-09-22 4 views
0

다른 방법을 호출하여 재생해야하는 두 가지 wav 파일이 있습니다. 하나의 wav 파일은 재생할 수 있지만 재생할 수는 없습니다. 내 코드하는 .miPhone SDK에서 두 가지 다른 사운드를 재생하는 방법은 무엇입니까?

-(void)correctSound { 
    NSString *sound = [[NSString alloc] initWithFormat:@"claps2"]; 
    NSLog(@"sound claps %@", sound); 
    NSURL *url = [[NSURL alloc] initFileURLWithPath:[[NSBundle mainBundle] pathForResource:sound ofType:@"wav"]]; 
    NSLog(@"claps url %@", url); 
    player1 = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil]; 

    player1.delegate = self; 
    player1.volume = 1.0; 
    [player1 prepareToPlay]; 
    [player1 play]; 

    [sound release]; 
    [url release]; 
} 

-(void)wrongSound { 
    NSString *sound1 = [[NSString alloc] initWithFormat:@"boo"]; 
    NSLog(@"sound boo %@", sound1); 
    NSURL *url1 = [[NSURL alloc] initFileURLWithPath:[[NSBundle mainBundle] pathForResource:sound1 ofType:@"wav"]]; 
    NSLog(@"boo url %@", url1); 
    NSError *error; 
    player2 = [[AVAudioPlayer alloc] initWithContentsOfURL:url1 error:&error]; 
    NSLog(@"localizedDescription = %@",[error localizedDescription]); 
    player2.delegate = self; 
    player2.volume = 1.0; 
    [player2 prepareToPlay]; 
    [player2 play]; 

    [sound1 release]; 
    [url1 release]; 
} 

업데이트 나는이 링크를 보았다 Play multiple audio files using AVAudioPlayer 에서 .H

AVAudioPlayer *player1, *player2; 

에서

을하지만, 그것은 나에게 도움이되지 않습니다. 어떻게 할 수 있습니까? 코드 샘플은 크게 감사하겠습니다. 콘솔에서 다음 오류 설명이 나타납니다.

localizedDescription = The operation couldn’t be completed. (OSStatus error 1685348671.) 

이 문제는 계속 발생하도록 도와주세요. 미리 감사드립니다.

답변

0

WAV 형식을 MP3로 변환하여 제 자신을 바로 잡았습니다. 지금 그것의 연주.

관련 문제