iPhone에서 버튼을 클릭 할 때마다 짧은 사운드를 재생하려고합니다. 그러나, 아래의 playClickSound 메서드를 호출하는 버튼을 클릭 할 때마다 어떤 이유로 사운드가 재생되지 않습니다. 프로젝트를 AudioFoundation.framework 및 사운드 파일 (clickSound.mp3)과 연결된 응용 프로그램 번들의 Resources 폴더에 있습니다. 누군가 제가 제가 누락 된 부분을 알아낼 수있게 도와 주시겠습니까? 왜 AVAudioPlayer가 내 사운드 파일을 재생하지 못하게합니까?겉으로보기에 단순한 AVAudioPlayer 코드는 iPhone에서 오디오 파일을 재생하지 않습니다.
- (void) playClickSound {
// Get path of sound file in bundle.
NSString *path = [[NSBundle mainBundle] pathForResource: @"clickSound" ofType: @"mp3"];
// Create url from path.
NSURL *url = [NSURL URLWithString: path];
// Create error.
NSError *error;
// Create audio player, and play file.
AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL: url error: &error];
if (![audioPlayer play]) {
[error localizedDescription];
}
[audioPlayer release];
} // playClickSound