LoginSignup
3
1

More than 5 years have passed since last update.

iOS AVAudioSessionモードを指定してカテゴリの動作を特殊化する

Last updated at Posted at 2015-07-09
NSError *error = nil;
AVAudioSession *audioSession = [AVAudioSession sharedInstance];

//オーディオセッションのカテゴリを設定する
BOOL success = [audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error:&error];
if(!success){NSLog(@"AudioSession setCategory error [%@]", [error localizedDescription]);}

//モードを指定してカテゴリの動作を特殊化する
success = [audioSession setMode:AVAudioSessionModeVideoChat error:&error];
if(!success){NSLog(@"AudioSession setMode error [%@]", [error localizedDescription]);}

//オーディオセッションを作動する
success = [audioSession setActive:YES error:&error];
if(!success){NSLog(@"AudioSession setActive error [%@]", [error localizedDescription]);}

NSError *error = nil;
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
//setActiveプロパティをNOとすれば、オーディオセッションは停止します。
BOOL success = [audioSession setActive:NO withOptions:AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation error:&error];
if(!success){NSLog(@"AudioSession setActive error [%@]", [error localizedDescription]);}

(追記)
ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー
// モードを指定せず、AirPlay切り替え可 + ディフォルトSpeaker出力
NSError *error = nil;
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
BOOL success = [audioSession setCategory:AVAudioSessionCategoryPlayAndRecord
                             withOptions:(AVAudioSessionCategoryOptionDefaultToSpeaker |
                                          AVAudioSessionCategoryOptionAllowBluetooth)
                                   error:&error];
if(!success){NSLog(@"AudioSession setCategory error [%@]", [error localizedDescription]);}

success = [audioSession setActive:YES error:&error];
if(!success){NSLog(@"AudioSession setActive error [%@]", [error localizedDescription]);}

● AVAudioSessionModeDefault:
どのカテゴリに対しても指定できる既定のモードで、デバイスの汎用的な使い方に向いています。

● AVAudioSessionModeVoiceChat:
VoIP(Voice over IP)アプリケーション用。
AVAudioSessionCategoryPlayAndRecordカテゴリの場合にのみ指定できます。システム組み込
みの信号処理系で、人の声として最適な形に処理します。
AVAudioSessionCategoryOptionAllowBluetoothも設定します。
利用可能な一連の音声経路は、ボイスチャット用に最適化されます。組み込みマイクを使う場
合、システムは自動的に、ボイスチャット用に最適な組み合わせを選択します。

● AVAudioSessionModeVideoChat:
FaceTimeなどのビデオチャットアプリケーションに向いています。
AVAudioSessionCategoryPlayAndRecordカテゴリの場合にのみ指定できます。システム
組み込みの信号処理系で、人の声として最適な形に処理します。
AVAudioSessionCategoryOptionAllowBluetoothおよび
AVAudioSessionCategoryOptionDefaultToSpeakerも設定します。

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1