What's the difference between .setPreferredInput(_ inPort: AVAudioSessionPortDescription?)
and .setPreferredDataSource(_ dataSource: AVAudioSessionDataSourceDescription?)
?
Both functions can be used to determine the active or preferred microphone.
By calling:
import AVFoundation
let availableInputs = AVAudioSession.sharedInstance().availableInputs
I have an array containing built-in microphones, maybe an earphone microphone if connected, and so on. Each value in this array can be passed as a single argument to both functions. In the Data Source situation, you can pass it as an argument by calling availableInputs![0].dataSources
, for example.
Is there any difference between them? How and when using them? .setPreferredDataSource(...)
is more generic and can be called for input and output devices, but besides it, I can't see much difference between them.
I got a explanation here in the documentation, but it doesn't help much:
Setting a Preferred Input:
To discover built-in or connected input
ports, use the audio session’s availableInputs property. This property
returns an array of AVAudioSessionPortDescription objects that
describe the device’s available input ports. Ports can be identified
by their portType property. To set a preferred input port (built-in
microphone, wired microphone, USB input, and so on) use the audio
session’s setPreferredInput:error: method.
Setting a Preferred Data Source:
Some ports, such as the built-in
microphone and some USB accessories, support data sources. Apps can
discover available data sources by querying the port description’s
dataSources property. In the case of the built-in microphone, the
returned data source description objects represent each individual
microphone. Different devices return different values for the built-in
mic. For instance, the iPhone 4 and iPhone 4S have two microphones:
bottom and top. The iPhone 5 has three microphones: bottom, front, and
back.
Individual built-in microphones may be identified by a combination of
a data source description’s location property (upper, lower) and
orientation property (front, back, and so on). Apps may set a
preferred data source by using the setPreferredDataSource:error:
method of an AVAudioSessionPortDescription object.
question from:
https://stackoverflow.com/questions/65911729/whats-the-difference-between-setpreferredinput-and-setpreferreddatasourc