iOS Изменить устройство динамик с датчиком приближения
У меня есть плеер, транслирующий видео и аудио с облачной камеры.
Я пытаюсь настроить вывод звука. звук выходит из двух динамиков (ухо и ниже). Прямо сейчас...
но я не хочу чтобы он выходил через динамик ниже при включенном датчике
[[UIDevice currentDevice] setProximityMonitoringEnabled:YES];
[notificationCenter addObserver:self selector:@selector(sensorStateMonitor:) name:@"UIDeviceProximityStateDidChangeNotification" object:nil];
,
_audioSession = [AVAudioSession sharedInstance];
[_audioSession setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionDefaultToSpeaker error:nil];
[_audioSession setActive:YES withOptions:AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation error:nil];
,
- (void)sensorStateMonitor:(NSNotificationCenter *)notification
{
if ([[UIDevice currentDevice] proximityState] == YES){
NSLog(@"Device is close to user.");
[_audioSession overrideOutputAudioPort:AVAudioSessionPortOverrideNone error:nil];
}
else{
[_audioSession overrideOutputAudioPort:AVAudioSessionPortOverrideSpeaker error:nil];
NSLog(@"Device is not closer to user.");
}
[_audioSession setActive:YES error:nil];
NSLog(@"Current audio route: %@",_audioSession.currentRoute.outputs);
}
когда активны датчики у меня есть этот журнал
Устройство близко к пользователю.[Avas] AVAudioSessionPortImpl.mm:56:ValidateRequiredFields: Неизвестный выбранный источник данных для Port Receptor (тип: Receiver) Текущий аудио маршрут: (AVAudioSessionPortDescription: 0x2813d8020, type = Receiver; name = Receptor; UID = Built- В Receiver; selectedDataSource = (null))
и когда датчик выключен этот журнал
Устройство не ближе к пользователю.[avas] AVAudioSessionPortImpl.mm:56:ValidateRequiredFields: Неизвестный выбранный источник данных для порта Bocina (тип: Speaker) Текущий аудио маршрут: (AVAudioSessionPortDescription: 0x2813d2620, тип = Speaker; name = Bocina; UID = Speaker; selectedDataSource = null) (null): null ")
но звук всегда выходит через два динамика