当 iOS 睡眠定时器被调用时,我想停止我的音频应用程序。
就像潘多拉应用程序一样。
http://help.pandora.com/customer/portal/articles/24324-ios-sleep-timer-with-pandora
点击时钟应用程序,点击计时器,选择时间,点击计时器结束时,点击停止播放
如果 Pandora 应用程序正在运行,这将使它进入睡眠状态。
我可以看到 inInterruptionState == kAudioSessionBeginInterruption 在 iOS 睡眠定时器结束时被调用,但是我如何检测它是睡眠定时器还是只是像电话呼叫这样的中断?
这是我的代码。目前,我的应用程序在 iOS 睡眠定时器结束后才重新开始播放。
// Audio Interruption Listener
void MyInterruptionListener(void *inClientData, UInt32 inInterruptionState) {
if (inInterruptionState == kAudioSessionBeginInterruption) {
[[DOSpeechManager sharedInstance] audioSessionBeginInterruption];
}
if (inInterruptionState == kAudioSessionEndInterruption) {
[[DOSpeechManager sharedInstance] audioSessionEndInterruption];
}
}
- (void)audioSessionBeginInterruption {
if ([_MyAcaTTS isSpeaking] && [_MyAcaTTS isPaused] == NO) {
[_MyAcaTTS pauseSpeakingAtBoundary:AcapelaSpeechImmediateBoundary];
[self setAudioSettionStatus:NO];
_audioInterruptedWhileSpeaking = YES;
}
}
- (void)audioSessionEndInterruption {
if (_audioInterruptedWhileSpeaking) {
[self setAudioSettionStatus:YES];
[_MyAcaTTS continueSpeaking];
}
}
- (void)setAudioSettionStatus:(BOOL)status {
AudioSessionSetActive(status);
[_MyAcaTTS setActive:status];
//cancel audio interrupted flag
if (status) {
_audioInterruptedWhileSpeaking = NO;
}
}