다른 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 기기에서는 다시 호출 할 때 재생을 시작하지 않습니다.
감사합니다. 워드 프로세서
적어도이 장치를 테스트 한 결과이 문제가 해결 된 것 같습니다. 적절한 해결책이 될 수는 없지만 새로운 viewController 내부에서 플레이어를 다시 초기화하면 작동하는 것 같습니다. 또한이 viewController에서 menuLoop을 속성으로 나열했습니다. 이제 괜찮아 보인다. 모두에게 감사드립니다. – Fluffhead