아래 전화에서 내 앱에서 네 가지 사운드에 대한 AVAudioPlayer를 준비 중입니다. 이 작업을 수행하지 않으면 응용 프로그램이 약 1.5 초 지연됩니다. 단지 듣고 싶은 부분에서만 수행합니다. 그래서이 코드를 더보기 좋게 만들거나 더 효율적으로 작업 할 수있는 방법이 있습니까? 지금은 App-Delegate에서이 사운드를 준비하고 있기 때문에 조금 늦어집니다. 그래서 여기 코드는 더 나은 다음이 코드를 만들 수있는 방법이 있다면 알려주세요 : 초기화 시간이 귀하의 유일한 관심사 경우효율적인 코드? (AVAudioPlayer)
- (void)readySounds {
NSString *path = [[NSBundle mainBundle] pathForResource:@"TrackUno" ofType:@"mp3"];
NSURL *file = [[NSURL alloc] initFileURLWithPath:path];
AVAudioPlayer *one = [[AVAudioPlayer alloc] initWithContentsOfURL:file error:nil];
[file release];
self.tr1 = one;
[one release];
[tr1 prepareToPlay];
[tr1 setDelegate:self];
NSString *path2 = [[NSBundle mainBundle] pathForResource:@"TrackDos" ofType:@"mp3"];
NSURL *file2 = [[NSURL alloc] initFileURLWithPath:path2];
AVAudioPlayer *two = [[AVAudioPlayer alloc] initWithContentsOfURL:file2 error:nil];
[file2 release];
self.tr2 = two;
[two release];
[tr2 prepareToPlay];
[tr2 setDelegate:self];
NSString *path3 = [[NSBundle mainBundle] pathForResource:@"Click" ofType:@"mp3"];
NSURL *file3 = [[NSURL alloc] initFileURLWithPath:path3];
AVAudioPlayer *three = [[AVAudioPlayer alloc] initWithContentsOfURL:file3 error:nil];
[file3 release];
self.clk = three;
[three release];
[clk prepareToPlay];
[clk setDelegate:self];
NSString *path4 = [[NSBundle mainBundle] pathForResource:@"HSSound" ofType:@"mp3"];
NSURL *file4 = [[NSURL alloc] initFileURLWithPath:path4];
AVAudioPlayer *four = [[AVAudioPlayer alloc] initWithContentsOfURL:file4 error:nil];
[file4 release];
self.hs = four;
[four release];
[hs prepareToPlay];
[hs setDelegate:self];
}
어떻게하면 리팩터링하여 더보기 좋게 만들 수 있습니까? –
@MyApps 업데이트 – justin
Ohhh nice, btw이 줄은 다음과 같습니다. NSURL * url = [bundle URLForResource : fileName withExtension : extension]; 또한 보조 스레드에서 이것이 가장 효율적 일 수 있습니까? 편집 : 축하해 12K에! –