オーディオがどのように停止されたか (電話しました[self.audioPlayer stop]
か?) によっては、再度電話をかける[self.audioPlayer prepareToPlay]
前に電話する必要がある場合がありますplay
。
あなたがすべきことは次のことだと思います。
-(void)audioPlayerBeginInterruption:(AVAudioPlayer *)audioPlayer;
{
[self.audioPlayer一時停止];
}
-(void)audioPlayerEndInterruption:(AVAudioPlayer *)audioPlayer;
{
[self.audioPlayer プレイ];
}
私の経験では、電話をかけstop
たら、もう一度電話prepareToPlay
する前に電話する必要がありますplay
。
編集:
または、AudioSession を介して直接割り込みを処理する必要がある場合があります。
アプリは AudioSession を次のように初期化する必要があります。
AudioSessionInitialize(NULL, NULL, AudioInterruptionListener, NULL);
次に、 /ブロックのAudioInterruptionListener
外側に次のように実装します。@implementation
@end
#define kAudioEndInterruption @"AudioEndInterruptionNotification"
#define kAudioBeginInterruption @"AudioBeginInterruptionNotification"
void AudioInterruptionListener (
void *inClientData,
UInt32 inInterruptionState
)
{
NSString *notificationName = nil;
スイッチ (inInterruptionState) {
kAudioSessionEndInterruption の場合:
notificationName = kAudioEndInterruption;
壊す;
kAudioSessionBeginInterruption の場合:
notificationName = kAudioBeginInterruption;
壊す;
デフォルト:
壊す;
}
if (通知名) {
NSNotification *notice = [NSNotification notificationWithName:notificationName object:nil];
[[NSNotificationCenter defaultCenter] postNotification:通知];
}
}
Objective-C に戻り、このコードが投稿する可能性のある通知をリッスンする必要があります。次のようになります。
// 音声割り込みの開始/終了をリッスンします
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(beginAudioInterruption:)
名前:kAudioBeginInterruption オブジェクト:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(endAudioInterruption:)
名前:kAudioEndInterruption オブジェクト:nil];
と:
-(void)beginAudioInterruption:(id)コンテキスト
{
[self.audioPlayer一時停止];
}
-(void)endAudioInterruption:(id)context
{
[self.audioPlayer プレイ];
}
回転させてください。:-)