2012-12-02 2 views
3

를 OpenAL을 사용하여 사운드 및 BG 음악까지, 수신 통화 후 재생되지 않습니다 소리. 최근에 나는 전화가 들어오고 나면 bg 음악이 여전히 재생되는 동안 모든 개방 음이 작동하지 않는다는 것을 알게되었습니다. 앱을 강제 종료하고 다시 시작하면 소리가 다시 나타납니다. smbd는 들어오는 통화 도중/열리는 중에 어떤 일이 일어나고 있는지 알 수 있습니까?개방 등 표준 AV를 사용하여 내가 게임을하고있어 응용 프로그램을 다시 시작

+0

은 그냥 발견 : http://developer.apple.com/library/ios/documentation/Audio/Conceptual/AudioSessionProgrammingGuide/Cookbook/Cookbook.html#//apple_ref/doc/uid/TP40007875-CH6- SW38. 무엇이 잘못되었는지 이해해야합니다. – Tertium

답변

1

좋아, 해결책을 찾은 것 같습니다. obj-c 사운드 관리자를 사용하기 때문에 AVAudioSession (및 AVAudioPlayer)의 beginInterruption 및 endInterruption 대리자 메서드를 클래스에 추가했습니다.

beginInterruption은 다음과 같습니다

alcMakeContextCurrent(NULL); 

및 endInterruption는 같은 같습니다

NSError * audioSessionError = NULL; 
    [audioSession setCategory:soundCategory error:&audioSessionError]; 
    if (audioSessionError) 
    { 
     Log(@"ERROR - SoundManager: Unable to set the audio session category"); 
     return; 
    } 

    // Set the audio session state to true and report any errors 
    audioSessionError = NULL; 
    [audioSession setActive:YES error:&audioSessionError]; 
    if (audioSessionError) 
    { 
     Log(@"ERROR - SoundManager: Unable to set the audio session state to YES with error %d.", (int) result); 
     return; 
    } 

     //music players handling 
    bool plays = false; 
    if (musicPlayer[currentPlayer] != nil) 
     plays = [musicPlayer[currentPlayer] isPlaying]; 
    if (musicPlayer[currentPlayer] != nil && !plays) 
     [musicPlayer[currentPlayer] play]; 

    alcMakeContextCurrent(context); 

만 OpenAL에 소리를 사용하는 경우 예,이 작품을. 그러나 긴 트랙을 재생하려면 AVAudioPlayer를 사용해야합니다. 하지만 여기에 애플 마법이 있습니다! OpenAL과 함께 음악을 연주하면 이상한 일이 발생합니다. AVAudioPlayerDelegate :: audioPlayerEndInterruption을 호출하지 않고 들어오는 호출을 취소하고 AVAudioSessionDelegate :: endInterruption을 호출하지 않습니다. 끝이 아니라 시작 만이 시작됩니다. 심지어 AppDelegate :: applicationWillEnterForeground도 호출되지 않으며 앱은 우리가 반환했음을 알지 못합니다.

하지만 좋은 소식은 AppDelegate :: applicationDidBecomeActive 메서드에서 endInterruption을 호출하면 openAL 컨텍스트가 복원된다는 것입니다. 그리고이 작품!

- (void)applicationDidBecomeActive:(UIApplication *)application 
{ 
    if (MySoundMngr != nil) 
    { 
     [MySoundMngr endInterruption]; 
    } 

    // Restart any tasks that were paused and so on.... 
} 
+0

저는 여전히 iOS 10에서 이러한 종류의 문제를 겪고 있습니다. '중단'은'AVAudio'를 위해 고안된 것 같습니다. 'OpenAL'도 중단해야한다는 뜻입니까? – jayatubi

+0

모든 두통을 피하기 위해 객관적인 C에서 writting을 중단하고 xamarin 및 C# (VS2015 + Xamarin은 현재 무료)을 사용하기 시작했습니다. 버그 코드 xcode 및 추한 언어로 인해 개발하는 동안 문제가 발생해도 응용 프로그램이 작동하지 않습니다. 아니요, 너무 나빠요. 이제 사람들에게 대안이 있습니다. 적어도 내가 기쁨으로 개발 :) – Tertium