视频播放里有很多场景。
当我们的视频播放需要支持列表里静音播放,并且不打断外部音频播放。点击进入视频详情有声音,并且暂时打断外部音频,当视频播放完成以后,就恢复外部音频
列表里播放时设置AVAudioSession:
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback mode:AVAudioSessionModeDefault options:AVAudioSessionCategoryOptionInterruptSpokenAudioAndMixWithOthers error:nil];
[[AVAudioSession sharedInstance] setActive:YES error:nil];
AVAudioSessionCategoryOptionInterruptSpokenAudioAndMixWithOthers 允许混音
进入视频详情后设置AVAudioSession:
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient mode:AVAudioSessionModeDefault options:AVAudioSessionCategoryOptionAllowBluetooth error:nil];
[[AVAudioSession sharedInstance] setActive:NO withOptions:AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation error:nil];
AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation 恢复外部音频,如音乐