![](/img/trans.png)
[英]how to remove cell index when timer gets complete after 5 min ios swift 5 , when called api not repeat timeragain of same index
[英]how to stop audio when iOS Sleep Timer gets called
我想在iOS睡眠計時器被調用時停止我的音頻應用程序。
就像Pandora應用一樣。
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;
}
}
訣竅不是要檢測中斷源,而是要知道您的應用在中斷后是否應繼續運行。
音頻會話中斷時,AVAudioSession API將發送通知。 在此通知中,操作系統會“提示”應用程序是否應繼續播放。
見下文:
//Add notification observer
__weak typeof(self) weakSelf = self;
self.audioSessionInterruptionNotification =
[[NSNotificationCenter defaultCenter] addObserverForName:AVAudioSessionInterruptionNotification
object:nil
queue:[NSOperationQueue mainQueue]
usingBlock:^(NSNotification *note) {
NSNumber* interruptionType = note.userInfo[AVAudioSessionInterruptionTypeKey];
NSNumber* interruptionOption = note.userInfo[AVAudioSessionInterruptionOptionKey];
BOOL shouldResume = interruptionOption.integerValue == AVAudioSessionInterruptionOptionShouldResume;
switch (interruptionType.integerValue) {
case AVAudioSessionInterruptionTypeBegan:
[weakSelf beginInterruption];
break;
case AVAudioSessionInterruptionTypeEnded:
[weakSelf endInterruption:shouldResume];
break;
default:
break;
}
}];
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.