开发者

kAudioSessionProperty_OtherMixableAudioShouldDuck some times music does not unduck

I am using MPMusicPlayerController to play music from device with iPodMusicPlayer. And at regular intervals play alerts with AVPlayer. Code goes like this

-(void) duckMusic
{
    UInt32 on=1;   
    AudioSes开发者_如何学PythonsionSetProperty(kAudioSessionProperty_OtherMixableAudioShouldDuck,sizeof(on),&on);
    AudioSessionSetActive(true);
}

-(void) unDuckMusic
{
    UInt32 on=0;
    AudioSessionSetProperty(kAudioSessionProperty_OtherMixableAudioShouldDuck,sizeof(on),&on);
    AudioSessionSetActive(false);
}

I call the first method just before playing the alert and I call the second method after recieving notification AVPlayerItemDidPlayToEndTimeNotification

The problem I am getting is that some times the music does not fade back after alert is completed. With some debugging I have found that the audio session property is being set properly but it is being ignored for some reason.

I have also noticed while testing, that when music does not fade back, if I just pause and play music manually on device it becomes to normal.

How to handle this programmatically?

Edit:

The problem is coming when application is running in background


You shouldn't need to set the property in unDuckMusic, deactivating the session should be enough to allow mixed audio to return to normal volume.

I had a similar problem when my audio session was not correctly handling an audio interruption while backgrounded, which caused audio session calls to fail in unpredictable ways. So make sure you handle those.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜