0
NSString *musicPath = [[NSBundle mainBundle] pathForResource:@"ding" ofType:@"mp3"];
if (musicPath)
{
if(TapSoud)
{
[TapSoud release];
TapSoud = nil;
}
TapSoud = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:musicPath] error:nil];
}
[TapSoud setDelegate:self];
[TapSoud prepareToPlay];
[TapSoud play];
NSString *musicPath1 = [[NSBundle mainBundle] pathForResource:@"roadrunner" ofType:@"mp3"];
if (musicPath1)
{
if(MatchSoud)
{
[MatchSoud release];
MatchSoud = nil;
}
MatchSoud = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:musicPath1] error:nil];
}
[MatchSoud setDelegate:self];
[MatchSoud prepareToPlay];
NSString *musicPath2 = [[NSBundle mainBundle] pathForResource:@"Wrong Answer" ofType:@"wav"];
if (musicPath2)
{
if(WrongMatchSoud)
{
[WrongMatchSoud release];
WrongMatchSoud = nil;
}
WrongMatchSoud = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:musicPath2] error:nil];
}
[WrongMatchSoud setDelegate:self];
[WrongMatchSoud prepareToPlay];
이 코드는 시뮬레이터에서 제대로 작동하지만 장치에서 소리가 나지 않습니다. 여기에 어떤 문제가 있습니까?장치의 사운드 문제
왜 ARC를 사용하지 않습니까? 그것은 정말로 물건들을 단순화합니다. – mm24
패턴'if (x) {[x release]; x = nil; } x = [something]'은 [x release]로 단순화 될 수 있습니다; x = [뭔가]'. 이 경우,'if (x)'와'x = nil'은 중복됩니다. –