Apple がiOS 5mute/silence
で iPhoneスイッチの状態を検出する方法を提供していないことは知っています。ただし、オーディオ ファイルを再生し、そのランタイムを測定することでこれを検出するために、他の場所で言及されている手法を試しました。ただし、私の iPhone がミュートされていたとしても、オーディオ ファイルは引き続き全期間再生されました。が呼び出される前の時間を使用して計算しています。電話がミュートされている場合、音声ファイルを再生するトリックを知っていますか?[AVAudioPlayer play]
audioPlayerDidFinishPlaying
8779 次
1 に答える
4
更新:申し訳ありませんが、投稿された以下のコードは問題なく動作しますが、iOS4 を使用しています。iOS5 の場合、この回答はあなたの問題を解決するものです - Detecting the iPhone's Ring / Silent / Mute switch using AVAudioPlayer not working?
このコードが必要です。グローバル変数を定義しgAudioSessionInited
ます。このフラグは、ミュート スイッチがオンかオフかを示します。
// "Ambient" makes it respect the mute switch. Must call this once to init session
if (!gAudioSessionInited)
{
AudioSessionInterruptionListener inInterruptionListener = NULL;
OSStatus error;
if ((error = AudioSessionInitialize (NULL, NULL, inInterruptionListener, NULL)))
NSLog(@"*** Error *** error in AudioSessionInitialize: %d.", error);
else
gAudioSessionInited = YES;
}
SInt32 ambient = kAudioSessionCategory_AmbientSound;
if (AudioSessionSetProperty (kAudioSessionProperty_AudioCategory, sizeof (ambient), &ambient))
{
NSLog(@"*** Error *** could not set Session property to ambient.");
}
于 2011-11-16T20:23:28.107 に答える