2012-04-27 2 views
0

다른 ViewControllers에서 음악을 재생하고 제어하는 ​​앱이 있습니다.5.0에서 문제없이 작동하는 AVAudioPlayer는 4.0-4.3.5에서 발행됩니다.

- (IBAction)playGameLoop{ 

NSLog(@"Begin playGameLoop"); 
FPAppDelegate *app = (FPAppDelegate *)[[UIApplication sharedApplication] delegate]; 

if ([FPAVManager audioEnabled] == NO){ 
    //DO NOTHING 
} 
else { 
    if (app.gameLoop.playing ==YES) { 
     //DO NOTHING 
    } 
    else { [app.gameLoop play]; 
    NSLog(@"End playGameLoop"); 
    } 
    } 

오디오 파일 : 나는 중지하거나 같은 코드를 사용하여 다시 시작, 다양한 viewControllers의 호출이 후

NSString *path = [[NSBundle mainBundle] pathForResource:@"minnie1" ofType:@"mp3"]; 
NSURL *path1 = [[NSURL alloc] initFileURLWithPath:path]; 
menuLoop =[[AVAudioPlayer alloc] initWithContentsOfURL:path1 error:NULL]; 
[menuLoop setDelegate:self]; 
menuLoop.numberOfLoops = -1; 
[menuLoop play]; 


NSString *path2 = [[NSBundle mainBundle] pathForResource:@"minnie2" ofType:@"mp3"]; 
NSURL *path3 = [[NSURL alloc] initFileURLWithPath:path2]; 
gameLoop=[[AVAudioPlayer alloc] initWithContentsOfURL:path3 error:NULL]; 
gameLoop.numberOfLoops = -1; 
[gameLoop setDelegate:self]; 
[gameLoop prepareToPlay]; 

이렇게하려면, 나는 애플 대리자의 DidFinishLaunchingMethod에 AVAudioPLayer의 두 인스턴스를 생성 처음에는 잘 플레이하고 멈추라는 요청을 받으면 멈 춥니 다. iOS4 기기에서는 다시 호출 할 때 재생을 시작하지 않습니다.

감사합니다. 워드 프로세서

답변

0

: 당신이 소리를 반복하는

 
Calling this method [stop] or allowing a sound to finish playing, 
undoes the setup performed upon calling the play or prepareToPlay 
methods. 

The stop method does not reset the value of the currentTime property 
to 0. In other words, if you call stop during playback and then call 
play, playback resumes at the point where it left off. 

, 나는 stop를 호출하고 play를 호출 할 수 있기를 기대합니다. 그러나 나는 나 자신에게 달려 드는 퍼지 추억을 가지고있다. 나는 stop보다는 pause을 호출하는 것이 더 나은 해결책이라는 것을 알았습니다. 특히 나는 play에 다시 전화를 걸어서 재생을 다시 시작할 수 있습니다. stop을 호출하면 항상 내 경험에 따라 play을 호출하기 전에 prepareToPlay을 다시 호출해야합니다.

iOS4.x와 iOS5 간의 API 구현에 약간의 변경이있을 수 있습니다. 개발자 웹 사이트의 API 차이점을 확인해야합니다.

+0

적어도이 장치를 테스트 한 결과이 문제가 해결 된 것 같습니다. 적절한 해결책이 될 수는 없지만 새로운 viewController 내부에서 플레이어를 다시 초기화하면 작동하는 것 같습니다. 또한이 viewController에서 menuLoop을 속성으로 나열했습니다. 이제 괜찮아 보인다. 모두에게 감사드립니다. – Fluffhead

관련 문제