지나치게 UIImagePicker에 버튼이 있습니다.이 버튼을 클릭하면 소리가납니다. 이렇게하려면 프로젝트 리소스에 m4a 및 mp3 형식의 사운드 (테스트 용)가 있어야합니다.iPhone - AudioServicesPlaySystemSound 및 AVAudioPlayer로 재생되지 않는 사운드
m4a 및 mp3 형식으로 여러 가지 방법으로 사운드를 재생하려고하지만 시뮬레이터가 아닌 iPhone에서는 아무 것도 나가지 않습니다.
프레임 워크는 프로젝트에 포함됩니다.
#import <AudioToolBox/AudioToolbox.h>
#import <AVFoundation/AVAudioPlayer.h>
- (IBAction) click:(id)sender {
// Try
/*
SystemSoundID train;
AudioServicesCreateSystemSoundID(CFBundleCopyResourceURL(CFBundleGetMainBundle(), CFSTR("TheSound"), CFSTR("mp3"), NULL), &train);
AudioServicesPlaySystemSound(train);
*/
// Try
/*
NSError *error;
AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[[NSBundle mainBundle] URLForResource: @"TheSound" withExtension: @"mp3"] error:&error];
[audioPlayer play];
[audioPlayer release];
*/
// Try (works)
//AudioServicesPlayAlertSound(kSystemSoundID_Vibrate);
// Try
/*
SystemSoundID soundID;
NSURL *filePath = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"TheSound" ofType:@"mp3"] isDirectory:NO];
AudioServicesCreateSystemSoundID((CFURLRef)filePath, &soundID);
AudioServicesPlaySystemSound(soundID);
*/
NSLog(@"Clicked");
}
당신이 잘못 무슨 일이 일어나고 있는지 말해 줄 수 : 여기
내 샘플 코드인가?
정말 고마워요. – Oliver