2012-07-16 2 views
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]; 

이 코드는 시뮬레이터에서 제대로 작동하지만 장치에서 소리가 나지 않습니다. 여기에 어떤 문제가 있습니까?장치의 사운드 문제

+0

왜 ARC를 사용하지 않습니까? 그것은 정말로 물건들을 단순화합니다. – mm24

+1

패턴'if (x) {[x release]; x = nil; } x = [something]'은 [x release]로 단순화 될 수 있습니다; x = [뭔가]'. 이 경우,'if (x)'와'x = nil'은 중복됩니다. –

답변

1

가장 큰 문제는 프로젝트 또는 리소스 복사 단계에서 오디오 파일이 누락되었다는 것입니다. 시뮬레이터는 응용 프로그램이 시뮬레이터에서 완전히 제거 될 때까지 프로젝트에서 제거 된 경우에도 이전에 복사 된 리소스를 저장합니다.

musicPath, musicPath1musicPath2이 비어 있지 않고 유효하지 않은지 확인하십시오.

관련 문제