2010-08-19 8 views
1

나는이 코드를 사용하여 사운드를 재생하지만 처음 재생할 때로드하는 데 5 초가 걸립니다.코코아 터치 - 로딩 AVAudioPlayer

어떻게하면 속도를 높일 수 있습니까?

-(IBAction)playSound{ //play the cricket noise 
NSString *soundPath = [[NSBundle mainBundle] pathForResource:@"Cricket_Sound" ofType:@"mp3"]; 
audioPlayer =[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:soundPath] error:NULL]; 
audioPlayer.delegate = self; 
[audioPlayer prepareToPlay]; 
audioPlayer.numberOfLoops = 0; 
[audioPlayer play]; 
} 

답변

0

당신은 viewDidLoad에서 코드의 다음 섹션을 넣어 시도 할 수 있도록 audioPlayer 인스턴스가 실제로 오디오 재생하도록 요청하기 전에 플레이 할 준비가되어 있음 :

NSString *soundPath = [[NSBundle mainBundle] pathForResource:@"Cricket_Sound" ofType:@"mp3"]; 
audioPlayer =[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:soundPath] error:NULL]; 
audioPlayer.delegate = self; 
[audioPlayer prepareToPlay]; 
audioPlayer.numberOfLoops = 0;