문제

Is it possible to output audio only to the iOS device's headphone jack and nowhere else? (e.g. not speakers nor bluetooth)

We're experimenting on a hardware add-on that receives input as tones from the audio jack. We could try detecting whether the headphone jack is connected, but that still leaves cases when there are bluetooth audio output devices are connected – we don't want the tones to be heard in the user's bluetooth headsets or speakers.

도움이 되었습니까?

해결책

You need read AudioSessionProgrammingGuide

You can get the current audio 'route' by calling AudioSessionGetProperty with the kAudioSessionProperty_AudioRoute property. This gives you a string such as "Headphone" or "Speaker" and play audio file receptively 'route' value

CFStringRef route;
UInt32 propertySize = sizeof(CFStringRef);
AudioSessionInitialize(NULL, NULL, NULL, NULL);
AudioSessionGetProperty(kAudioSessionProperty_AudioRoute, &propertySize, &route);

NSLog(@"%@ %@",route,kAudioSessionInputRoute_Headphone);
NSLog(@"%ld",CFStringGetLength(route));
if ([(__bridge NSString *)route isEqualToString:@"Headphone"])
{
    // play audio sound
}
else
{
     // not play audio sound
}

I hope it help you

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top