AVAudioSession endInterruption() returns an NSOSStatusErrorDomain

后端 未结 4 1377
眼角桃花
眼角桃花 2021-01-21 10:16

I\'m trying to solve an AVAudioSession problem since many hours ago and didn\'t get success!!

I found lots of guys talking about problems with endInterruption but none o

相关标签:
4条回答
  • 2021-01-21 10:56

    I solved the problem changing the way to design my audio code. Instead of use AVAudioSession and its delegate methods, I change to the C style to work with audio.

    I implemented the function:

    void interruptionListenerCallback (void *inUserData, UInt32 interruptionState) {}
    

    And it was initialized with:

    AudioSessionInitialize (NULL, NULL, interruptionListenerCallback, self);
    

    inside my -(id) init method.

    Hope it helps you also. Best.

    0 讨论(0)
  • 2021-01-21 10:56

    "If this delegate method receives the AVAudioSessionInterruptionFlags_ShouldResume constant in its flags parameter, the audio session is immediately ready to be used."

    You didn't handle the callback correctly. When you receive AVAudioSessionInterruptionFlags_ShouldResume, your audio session is ALREADY ready to use. You need to call setActive when you get a DIFFERENT flag.

    Hope it helps...

    0 讨论(0)
  • 2021-01-21 10:58

    use audiosession.setmode if it is voip

    0 讨论(0)
  • 2021-01-21 11:10

    Using @Trinca answer that what I did on "ARC'ed" project:

    AudioSessionInitialize (NULL, NULL, interruptionListenerCallback, (__bridge void *)(self.player));
    

    Were self.player is your player instance that you pass to the callback function.

    Then implement the callback:

    void interruptionListenerCallback (void *inUserData, UInt32 interruptionState) {
       NSLog(@"itnerp state %li",interruptionState);
       NSLog(@"inUserData %@",inUserData);
       AVAudioPlayer *pl = (__bridge AVAudioPlayer*)inUserData;
       switch (interruptionState) {
        case 0:
            [pl play];
        break;
    
        case 1:
            [pl pause];
        break;
       }
    
    }
    

    GOOD LUCK

    Shani

    0 讨论(0)
提交回复
热议问题