KVO on AudioSession isOtherAudioPlaying not working

I am trying to get notified when another sound is playing. I wanted to use KVO for this as it [[AVAudioSession sharedInstance] isOtherAudioPlaying]

is a property of the audio session.

My registration as an observer:

//start KVO on otherAudioIsPlaying
    [[AVAudioSession sharedInstance] addObserver:self
                                      forKeyPath:@"isOtherAudioPlaying"
                                         options:(NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld)
                                         context:nil];

      

My corresponding method:

-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{
NSLog(@"observe fired");
}

      

Why doesn't it work? AVAudioSession must be KVO compliant if it responds to the valueForKey selector, right?

My audio recording is activated before registering as an observer. Also, the session is being asked kAudioSessionProperty_OverrideCategoryMixWithOthers

what is the reason why I am not getting regular interruptions, so maybe this is the problem?

Even the deprecated function doesn't work:

AudioSessionAddPropertyListener(kAudioSessionProperty_OtherAudioIsPlaying, otherAudioPlaying , (__bridge void *)(self));

But if I type multiple times [[AVAudioSession sharedInstance] isOtherAudiPlaying]

, the value changes as expected.

Thanks for any hints!

+3


source to share





All Articles