Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
80 views
in Technique[技术] by (71.8m points)

ios - What's the difference between .setPreferredInput(...) and .setPreferredDataSource(...)?

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...