Мне нужно указать аудиовыходы, доступные для приложения iOS. Мой вопрос похож на этот: Как указать доступный маршрут вывода аудио на iOS
Я пробовал этот код:
NSError *setCategoryError = nil;
BOOL success = [[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback
error: &setCategoryError];
NSError *activationError = nil;
[[AVAudioSession sharedInstance] setActive: YES error: &activationError];
…
NSLog(@"session.currentRoute.outputs count %d", [[[[AVAudioSession sharedInstance] currentRoute] outputs ] count]);
for (AVAudioSessionPortDescription *portDesc in [[[AVAudioSession sharedInstance] currentRoute] outputs ]) {
NSLog(@"-----");
NSLog(@"portDesc UID %@", portDesc.UID);
NSLog(@"portDesc portName %@", portDesc.portName);
NSLog(@"portDesc portType %@", portDesc.portType);
NSLog(@"portDesc channels %@", portDesc.channels);
}
Однако я всегда вижу только один выходной порт (число равно 1), также, если у меня есть два (Airplay и встроенный динамик). Если я использую приложение "Музыка", я могу видеть оба порта и переключаться между ними. В моем приложении я вижу только тот, который я выбрал.
Есть что-то еще, что мне нужно сделать?
Спасибо
EDIT:
Я тоже пробовал этот код:
CFDictionaryRef asCFType = nil;
UInt32 dataSize = sizeof(asCFType);
AudioSessionGetProperty(kAudioSessionProperty_AudioRouteDescription, &dataSize, &asCFType);
NSDictionary *audioRoutesDesc = (__bridge NSDictionary *)asCFType;
NSLog(@"audioRoutesDesc %@", audioRoutesDesc);
но словарь содержит только один выход. Кроме того, массив входных источников пуст (у меня есть iPhone 4s)
EDIT2:
У меня что-то работает с помощью MPVolumeView. Этот компонент имеет кнопку, позволяющую выбрать выходной аудиомаршрут, например, в приложении "Музыка".
Если вы хотите, вы можете скрыть ползунок (и иметь только кнопку), используя:
self.myMPVolumeView.showsVolumeSlider = NO;