objc2_avf_audio/generated/AVAudioSession.rs
1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6use objc2_foundation::*;
7
8use crate::*;
9
10extern_class!(
11 /// [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudiosession?language=objc)
12 #[unsafe(super(NSObject))]
13 #[derive(Debug, PartialEq, Eq, Hash)]
14 pub struct AVAudioSession;
15);
16
17unsafe impl Send for AVAudioSession {}
18
19unsafe impl Sync for AVAudioSession {}
20
21extern_conformance!(
22 unsafe impl NSObjectProtocol for AVAudioSession {}
23);
24
25impl AVAudioSession {
26 extern_methods!(
27 /// Return singleton instance.
28 #[unsafe(method(sharedInstance))]
29 #[unsafe(method_family = none)]
30 pub unsafe fn sharedInstance() -> Retained<AVAudioSession>;
31
32 #[cfg(feature = "AVAudioSessionTypes")]
33 /// Get the list of categories available on the device. Certain categories may be unavailable on
34 /// particular devices. For example, AVAudioSessionCategoryRecord will not be available on devices
35 /// that have no support for audio input.
36 ///
37 /// This property is not atomic.
38 ///
39 /// # Safety
40 ///
41 /// This might not be thread-safe.
42 #[unsafe(method(availableCategories))]
43 #[unsafe(method_family = none)]
44 pub unsafe fn availableCategories(&self) -> Retained<NSArray<AVAudioSessionCategory>>;
45
46 #[cfg(feature = "AVAudioSessionTypes")]
47 /// Set session category.
48 #[unsafe(method(setCategory:error:_))]
49 #[unsafe(method_family = none)]
50 pub unsafe fn setCategory_error(
51 &self,
52 category: &AVAudioSessionCategory,
53 ) -> Result<(), Retained<NSError>>;
54
55 #[cfg(feature = "AVAudioSessionTypes")]
56 /// Set session category with options.
57 #[unsafe(method(setCategory:withOptions:error:_))]
58 #[unsafe(method_family = none)]
59 pub unsafe fn setCategory_withOptions_error(
60 &self,
61 category: &AVAudioSessionCategory,
62 options: AVAudioSessionCategoryOptions,
63 ) -> Result<(), Retained<NSError>>;
64
65 #[cfg(feature = "AVAudioSessionTypes")]
66 /// Set session category and mode with options.
67 #[unsafe(method(setCategory:mode:options:error:_))]
68 #[unsafe(method_family = none)]
69 pub unsafe fn setCategory_mode_options_error(
70 &self,
71 category: &AVAudioSessionCategory,
72 mode: &AVAudioSessionMode,
73 options: AVAudioSessionCategoryOptions,
74 ) -> Result<(), Retained<NSError>>;
75
76 #[cfg(feature = "AVAudioSessionTypes")]
77 /// Set session category, mode, routing sharing policy, and options.
78 ///
79 /// Use of the long-form route sharing policy is only valid in conjunction with a limited set of
80 /// category, mode, and option values.
81 ///
82 /// Allowed categories: AVAudioSessionCategoryPlayback.
83 ///
84 /// Allowed modes: AVAudioSessionModeDefault, AVAudioSessionModeMoviePlayback,
85 /// AVAudioSessionModeSpokenAudio.
86 ///
87 /// Allowed options: None. Options are allowed when changing the routing policy back to Default,
88 /// however.
89 #[unsafe(method(setCategory:mode:routeSharingPolicy:options:error:_))]
90 #[unsafe(method_family = none)]
91 pub unsafe fn setCategory_mode_routeSharingPolicy_options_error(
92 &self,
93 category: &AVAudioSessionCategory,
94 mode: &AVAudioSessionMode,
95 policy: AVAudioSessionRouteSharingPolicy,
96 options: AVAudioSessionCategoryOptions,
97 ) -> Result<(), Retained<NSError>>;
98
99 #[cfg(feature = "AVAudioSessionTypes")]
100 /// Get session category.
101 /// Examples: AVAudioSessionCategoryRecord, AVAudioSessionCategoryPlayAndRecord, etc.
102 #[unsafe(method(category))]
103 #[unsafe(method_family = none)]
104 pub unsafe fn category(&self) -> Retained<AVAudioSessionCategory>;
105
106 #[cfg(feature = "AVAudioSessionTypes")]
107 /// Get the current set of AVAudioSessionCategoryOptions.
108 #[unsafe(method(categoryOptions))]
109 #[unsafe(method_family = none)]
110 pub unsafe fn categoryOptions(&self) -> AVAudioSessionCategoryOptions;
111
112 #[cfg(feature = "AVAudioSessionTypes")]
113 /// Get the route sharing policy.
114 ///
115 /// See AVAudioSessionRouteSharingPolicy for a description of the available policies.
116 /// See setCategory:mode:routeSharingPolicy:options:error: for additional discussion.
117 #[unsafe(method(routeSharingPolicy))]
118 #[unsafe(method_family = none)]
119 pub unsafe fn routeSharingPolicy(&self) -> AVAudioSessionRouteSharingPolicy;
120
121 #[cfg(feature = "AVAudioSessionTypes")]
122 /// Get the list of modes available on the device. Certain modes may be unavailable on particular
123 /// devices. For example, AVAudioSessionModeVideoRecording will not be available on devices that
124 /// have no support for recording video.
125 #[unsafe(method(availableModes))]
126 #[unsafe(method_family = none)]
127 pub unsafe fn availableModes(&self) -> Retained<NSArray<AVAudioSessionMode>>;
128
129 #[cfg(feature = "AVAudioSessionTypes")]
130 /// Set the session's mode.
131 ///
132 /// Modes modify the audio category in order to introduce behavior that is tailored to the specific
133 /// use of audio within an application. Examples: AVAudioSessionModeVideoRecording,
134 /// AVAudioSessionModeVoiceChat, AVAudioSessionModeMeasurement, etc.
135 #[unsafe(method(setMode:error:_))]
136 #[unsafe(method_family = none)]
137 pub unsafe fn setMode_error(
138 &self,
139 mode: &AVAudioSessionMode,
140 ) -> Result<(), Retained<NSError>>;
141
142 #[cfg(feature = "AVAudioSessionTypes")]
143 /// Get the session's mode.
144 #[unsafe(method(mode))]
145 #[unsafe(method_family = none)]
146 pub unsafe fn mode(&self) -> Retained<AVAudioSessionMode>;
147
148 /// Set allowHapticsAndSystemSoundsDuringRecording to YES in order to allow system sounds and haptics to play while the session is actively using audio input.
149 /// Default value is NO.
150 #[unsafe(method(setAllowHapticsAndSystemSoundsDuringRecording:error:_))]
151 #[unsafe(method_family = none)]
152 pub unsafe fn setAllowHapticsAndSystemSoundsDuringRecording_error(
153 &self,
154 in_value: bool,
155 ) -> Result<(), Retained<NSError>>;
156
157 /// Whether system sounds and haptics can play while the session is actively using audio input.
158 #[unsafe(method(allowHapticsAndSystemSoundsDuringRecording))]
159 #[unsafe(method_family = none)]
160 pub unsafe fn allowHapticsAndSystemSoundsDuringRecording(&self) -> bool;
161
162 #[cfg(feature = "AVAudioSessionTypes")]
163 /// Returns an enum indicating whether the user has granted or denied permission to record, or has
164 /// not been asked
165 #[deprecated = "Please use AVAudioApplication recordPermission"]
166 #[unsafe(method(recordPermission))]
167 #[unsafe(method_family = none)]
168 pub unsafe fn recordPermission(&self) -> AVAudioSessionRecordPermission;
169
170 #[cfg(feature = "block2")]
171 /// Checks to see if calling process has permission to record audio.
172 ///
173 /// The 'response' block will be called immediately if permission has already been granted or
174 /// denied. Otherwise, it presents a dialog to notify the user and allow them to choose, and calls
175 /// the block once the UI has been dismissed. 'granted' indicates whether permission has been
176 /// granted. Note that the block may be called in a different thread context.
177 #[deprecated = "Please use AVAudioApplication requestRecordPermissionWithCompletionHandler"]
178 #[unsafe(method(requestRecordPermission:))]
179 #[unsafe(method_family = none)]
180 pub unsafe fn requestRecordPermission(&self, response: &block2::DynBlock<dyn Fn(Bool)>);
181
182 #[cfg(feature = "AVAudioSessionTypes")]
183 /// Use this method to temporarily override the output to built-in speaker.
184 ///
185 /// This method is only valid for a session using PlayAndRecord category. This change remains in
186 /// effect only until the current route changes or you call this method again with the
187 /// AVAudioSessionPortOverrideNone option. Sessions using PlayAndRecord category that always want to
188 /// prefer the built-in speaker output over the receiver, should use
189 /// AVAudioSessionCategoryOptionDefaultToSpeaker instead.
190 #[unsafe(method(overrideOutputAudioPort:error:_))]
191 #[unsafe(method_family = none)]
192 pub unsafe fn overrideOutputAudioPort_error(
193 &self,
194 port_override: AVAudioSessionPortOverride,
195 ) -> Result<(), Retained<NSError>>;
196
197 #[cfg(feature = "AVAudioSessionRoute")]
198 /// Select a preferred input port for audio routing.
199 ///
200 /// If the input port is already part of the current audio route, this will have no effect.
201 /// Otherwise, selecting an input port for routing will initiate a route change to use the preferred
202 /// input port. Setting a nil value will clear the preference.
203 #[unsafe(method(setPreferredInput:error:_))]
204 #[unsafe(method_family = none)]
205 pub unsafe fn setPreferredInput_error(
206 &self,
207 in_port: Option<&AVAudioSessionPortDescription>,
208 ) -> Result<(), Retained<NSError>>;
209
210 #[cfg(feature = "AVAudioSessionRoute")]
211 /// Get the preferred input port. Will be nil if no preference has been set.
212 #[unsafe(method(preferredInput))]
213 #[unsafe(method_family = none)]
214 pub unsafe fn preferredInput(&self) -> Option<Retained<AVAudioSessionPortDescription>>;
215
216 /// Set ringtone and alert interruption preference.
217 ///
218 /// Inform the system when the session prefers to not be interrupted by
219 /// ringtones and alerts. By setting this property to YES, clients will not be interrupted
220 /// by incoming call notifications and other alerts. Starting in iOS 14.0, users can set a global
221 /// preference for incoming call display style to "Banner" or "Full Screen". With "Banner" display style,
222 /// if below property is set to YES then system audio will be silenced. Thus, clients will not be interrupted
223 /// on incoming call notification and user will have opportunity to accept or decline the call. If call is declined,
224 /// the session will not be interrupted, but if user accepts the incoming call, the session will be interrupted.
225 /// With display style set as "Full Screen", below property will have no effect and clients will be
226 /// interrupted by incoming calls. Apps that record audio and/or video and apps that are used for
227 /// music performance are candidates for using this feature.
228 #[unsafe(method(setPrefersNoInterruptionsFromSystemAlerts:error:_))]
229 #[unsafe(method_family = none)]
230 pub unsafe fn setPrefersNoInterruptionsFromSystemAlerts_error(
231 &self,
232 in_value: bool,
233 ) -> Result<(), Retained<NSError>>;
234
235 /// This property is not atomic.
236 ///
237 /// # Safety
238 ///
239 /// This might not be thread-safe.
240 #[unsafe(method(prefersNoInterruptionsFromSystemAlerts))]
241 #[unsafe(method_family = none)]
242 pub unsafe fn prefersNoInterruptionsFromSystemAlerts(&self) -> bool;
243
244 #[cfg(feature = "AVAudioSessionTypes")]
245 /// Get the currently resolved rendering mode to badge content appropriately.
246 /// Clients should use this property to determine what to badge content as.
247 #[unsafe(method(renderingMode))]
248 #[unsafe(method_family = none)]
249 pub unsafe fn renderingMode(&self) -> AVAudioSessionRenderingMode;
250
251 /// Set a preference to enable echo cancelled input on supported hardware
252 ///
253 /// Applications might want to record the built-in microphone's input while also playing audio out via the built-in speaker.
254 /// Enabling echo cancelled input is useful when the application needs the input signal to be clear of any echoes
255 /// from the audio playing out of the built-in speaker.
256 ///
257 /// Audio sessions using Voice Processor don't need this option as echo cancellation is implicitly applied for those routes.
258 /// The Voice Processor solution is tuned for voice signals, unlike this option, which is tuned for better capture
259 /// of wider range of audio signals in the presence of built-in speaker echo.
260 ///
261 /// This option is valid only when used with AVAudioSessionCategoryPlayAndRecord and AVAudioSessionModeDefault and is only available
262 /// on certain 2024 or later iPhone models. Support can be queried using property `isEchoCancelledInputAvailable`.
263 /// Other recording sessions might be interrupted if this option is not compatible with sessions that are already recording.
264 ///
265 /// After an audio session goes active, `isEchoCancelledInputEnabled` property can be queried to check if the option was honored.
266 /// Note that the enabled state may change after route changes, e.g. if user plugs in a headset, that route might not support echo cancellation.
267 #[unsafe(method(setPrefersEchoCancelledInput:error:_))]
268 #[unsafe(method_family = none)]
269 pub unsafe fn setPrefersEchoCancelledInput_error(
270 &self,
271 value: bool,
272 ) -> Result<(), Retained<NSError>>;
273
274 /// This property is not atomic.
275 ///
276 /// # Safety
277 ///
278 /// This might not be thread-safe.
279 #[unsafe(method(prefersEchoCancelledInput))]
280 #[unsafe(method_family = none)]
281 pub unsafe fn prefersEchoCancelledInput(&self) -> bool;
282
283 /// Returns YES if echo cancelled input is successfully enabled on an active session.
284 /// Please see `prefersEchoCancelledInput` above for more details.
285 ///
286 /// This property is not atomic.
287 ///
288 /// # Safety
289 ///
290 /// This might not be thread-safe.
291 #[unsafe(method(isEchoCancelledInputEnabled))]
292 #[unsafe(method_family = none)]
293 pub unsafe fn isEchoCancelledInputEnabled(&self) -> bool;
294
295 /// Query whether built-in mic / built-in speaker route supports echo cancellation for the session's given category and mode.
296 /// Returns YES if device model supports echo cancellation and the audio category is PlayAndRecord and the mode is Default.
297 ///
298 /// This property is not atomic.
299 ///
300 /// # Safety
301 ///
302 /// This might not be thread-safe.
303 #[unsafe(method(isEchoCancelledInputAvailable))]
304 #[unsafe(method_family = none)]
305 pub unsafe fn isEchoCancelledInputAvailable(&self) -> bool;
306
307 /// Sets a Boolean value to inform the system to mute the session's output audio. The default value is false (unmuted).
308 ///
309 /// This property is supported with all categories and modes, except for
310 /// ``AVAudioSessionCategoryPlayAndRecord`` where it is only supported with ``AVAudioSessionModeDefault``.
311 /// Changing the mode to non-default mode with ``AVAudioSessionCategoryPlayAndRecord``
312 /// category will cause the session to unmute.
313 ///
314 /// Changes in output mute state can be observed via ``AVAudioSessionOutputMuteStateChangeNotification``.
315 /// If this value is set to true, ``AVAudioSessionUserIntentToUnmuteOutputNotification``
316 /// may be sent when a user hints to unmute by changing the volume.
317 ///
318 /// - Note: This will not mute system sounds and haptics.
319 ///
320 /// - Parameters:
321 /// - `muted`: A Boolean value to set the audio output to the desired muted state.
322 /// - `error`: A pointer to an error object. If an error occurs, the framework sets the pointer to an error object that describes the failure.
323 #[unsafe(method(setOutputMuted:error:_))]
324 #[unsafe(method_family = none)]
325 pub unsafe fn setOutputMuted_error(&self, muted: bool) -> Result<(), Retained<NSError>>;
326
327 /// A Boolean value that indicates whether audio output is in a muted state.
328 #[unsafe(method(isOutputMuted))]
329 #[unsafe(method_family = none)]
330 pub unsafe fn isOutputMuted(&self) -> bool;
331 );
332}
333
334/// Activation.
335impl AVAudioSession {
336 extern_methods!(
337 /// Set the session active or inactive.
338 ///
339 /// Note that activating an audio session is a synchronous (blocking) operation.
340 /// Therefore, we recommend that applications not activate their session from a thread where a long
341 /// blocking operation will be problematic.
342 /// Apps may activate a AVAudioSessionCategoryPlayback session when another app is hosting a
343 /// call (to start a SharePlay activity for example). However, they are not permitted to capture the
344 /// microphone of the active call, so attempts to activate a session with category
345 /// AVAudioSessionCategoryRecord or AVAudioSessionCategoryPlayAndRecord will fail with error
346 /// AVAudioSessionErrorCodeInsufficientPriority.
347 /// When deactivating a session, the caller is required to
348 /// first stop or pause all running I/Os (e.g. audio queues, players, recorders, converters,
349 /// remote I/Os, etc.). Starting in iOS 8, if the session has running I/Os at the time that
350 /// deactivation is requested, the session will be deactivated, but the method will return NO and
351 /// populate the NSError with the code property set to AVAudioSessionErrorCodeIsBusy to indicate the
352 /// misuse of the API. Prior to iOS 8, the session would have remained active if it had running I/Os
353 /// at the time of the deactivation request. Starting in iOS 19.0, deactivating while IO is running will
354 /// no longer return AVAudioSessionErrorCodeIsBusy.
355 #[unsafe(method(setActive:error:_))]
356 #[unsafe(method_family = none)]
357 pub unsafe fn setActive_error(&self, active: bool) -> Result<(), Retained<NSError>>;
358
359 #[cfg(feature = "AVAudioSessionTypes")]
360 #[unsafe(method(setActive:withOptions:error:_))]
361 #[unsafe(method_family = none)]
362 pub unsafe fn setActive_withOptions_error(
363 &self,
364 active: bool,
365 options: AVAudioSessionSetActiveOptions,
366 ) -> Result<(), Retained<NSError>>;
367
368 #[cfg(all(feature = "AVAudioSessionTypes", feature = "block2"))]
369 /// Asynchronously activate the session.
370 ///
371 /// This is a relatively time consuming operation. The completion handler will be called when the
372 /// activation completes or if an error occurs while attempting to activate the session. If the
373 /// session is configured to use AVAudioSessionRouteSharingPolicyLongFormAudio on watchOS, this
374 /// method will also cause a route picker to be presented to the user in cases where an appropriate
375 /// output route has not already been selected automatically. watchOS apps using
376 /// AVAudioSessionRouteSharingPolicyLongFormAudio should be prepared for this method to fail if no
377 /// eligible audio route can be activated or if the user cancels the route picker view.
378 #[unsafe(method(activateWithOptions:completionHandler:))]
379 #[unsafe(method_family = none)]
380 pub unsafe fn activateWithOptions_completionHandler(
381 &self,
382 options: AVAudioSessionActivationOptions,
383 handler: &block2::DynBlock<dyn Fn(Bool, *mut NSError)>,
384 );
385 );
386}
387
388/// AVAudioSessionHardwareConfiguration.
389///
390/// this category deals with the set of properties that reflect the current state of
391/// audio hardware in the current route. Applications whose functionality depends on these
392/// properties should reevaluate them any time the route changes.
393impl AVAudioSession {
394 extern_methods!(
395 /// The preferred hardware sample rate for the session. The actual sample rate may be different.
396 #[unsafe(method(setPreferredSampleRate:error:_))]
397 #[unsafe(method_family = none)]
398 pub unsafe fn setPreferredSampleRate_error(
399 &self,
400 sample_rate: c_double,
401 ) -> Result<(), Retained<NSError>>;
402
403 #[unsafe(method(preferredSampleRate))]
404 #[unsafe(method_family = none)]
405 pub unsafe fn preferredSampleRate(&self) -> c_double;
406
407 /// The preferred hardware IO buffer duration in seconds. The actual IO buffer duration may be
408 /// different.
409 #[unsafe(method(setPreferredIOBufferDuration:error:_))]
410 #[unsafe(method_family = none)]
411 pub unsafe fn setPreferredIOBufferDuration_error(
412 &self,
413 duration: NSTimeInterval,
414 ) -> Result<(), Retained<NSError>>;
415
416 #[unsafe(method(preferredIOBufferDuration))]
417 #[unsafe(method_family = none)]
418 pub unsafe fn preferredIOBufferDuration(&self) -> NSTimeInterval;
419
420 /// Sets the number of input channels that the app would prefer for the current route
421 #[unsafe(method(setPreferredInputNumberOfChannels:error:_))]
422 #[unsafe(method_family = none)]
423 pub unsafe fn setPreferredInputNumberOfChannels_error(
424 &self,
425 count: NSInteger,
426 ) -> Result<(), Retained<NSError>>;
427
428 #[unsafe(method(preferredInputNumberOfChannels))]
429 #[unsafe(method_family = none)]
430 pub unsafe fn preferredInputNumberOfChannels(&self) -> NSInteger;
431
432 /// Sets the number of output channels that the app would prefer for the current route
433 #[unsafe(method(setPreferredOutputNumberOfChannels:error:_))]
434 #[unsafe(method_family = none)]
435 pub unsafe fn setPreferredOutputNumberOfChannels_error(
436 &self,
437 count: NSInteger,
438 ) -> Result<(), Retained<NSError>>;
439
440 #[unsafe(method(preferredOutputNumberOfChannels))]
441 #[unsafe(method_family = none)]
442 pub unsafe fn preferredOutputNumberOfChannels(&self) -> NSInteger;
443
444 #[cfg(feature = "AVAudioSessionTypes")]
445 /// Sets the preferred input orientation.
446 /// The input orientation determines which directions will be left and right
447 /// when a built-in mic data source with the AVAudioSessionPolarPatternStereo polar pattern is selected.
448 /// Typically, this orientation should match how the user is holding the device while recording, which will match
449 /// the application's interface orientation when a single app is on the screen.
450 /// The actual input orientation may be different, for example, if another app's session is in control of routing.
451 /// The input orientation is independent of the orientation property of an AVAudioSessionDataSourceDescription.
452 #[unsafe(method(setPreferredInputOrientation:error:_))]
453 #[unsafe(method_family = none)]
454 pub unsafe fn setPreferredInputOrientation_error(
455 &self,
456 orientation: AVAudioStereoOrientation,
457 ) -> Result<(), Retained<NSError>>;
458
459 #[cfg(feature = "AVAudioSessionTypes")]
460 #[unsafe(method(preferredInputOrientation))]
461 #[unsafe(method_family = none)]
462 pub unsafe fn preferredInputOrientation(&self) -> AVAudioStereoOrientation;
463
464 #[cfg(feature = "AVAudioSessionTypes")]
465 /// Describes the orientation of the input data source (valid for the built-in mic input data source when a stereo polar pattern is selected).
466 #[unsafe(method(inputOrientation))]
467 #[unsafe(method_family = none)]
468 pub unsafe fn inputOrientation(&self) -> AVAudioStereoOrientation;
469
470 /// Returns the largest number of audio input channels available for the current route
471 #[unsafe(method(maximumInputNumberOfChannels))]
472 #[unsafe(method_family = none)]
473 pub unsafe fn maximumInputNumberOfChannels(&self) -> NSInteger;
474
475 /// Returns the largest number of audio output channels available for the current route
476 #[unsafe(method(maximumOutputNumberOfChannels))]
477 #[unsafe(method_family = none)]
478 pub unsafe fn maximumOutputNumberOfChannels(&self) -> NSInteger;
479
480 /// A value defined over the range [0.0, 1.0], with 0.0 corresponding to the lowest analog
481 /// gain setting and 1.0 corresponding to the highest analog gain setting.
482 ///
483 /// Attempting to set values outside of the defined range will result in the value being "clamped"
484 /// to a valid input. This is a global input gain setting that applies to the current input source
485 /// for the entire system. When no applications are using the input gain control, the system will
486 /// restore the default input gain setting for the input source. Note that some audio accessories,
487 /// such as USB devices, may not have a default value. This property is only valid if
488 /// inputGainSettable is true. Note: inputGain is key-value observable.
489 #[unsafe(method(setInputGain:error:_))]
490 #[unsafe(method_family = none)]
491 pub unsafe fn setInputGain_error(&self, gain: c_float) -> Result<(), Retained<NSError>>;
492
493 /// value in range [0.0, 1.0]
494 #[unsafe(method(inputGain))]
495 #[unsafe(method_family = none)]
496 pub unsafe fn inputGain(&self) -> c_float;
497
498 /// True when audio input gain is available. Some input ports may not provide the ability to set the
499 /// input gain, so check this value before attempting to set input gain.
500 #[unsafe(method(isInputGainSettable))]
501 #[unsafe(method_family = none)]
502 pub unsafe fn isInputGainSettable(&self) -> bool;
503
504 /// True if input hardware is available. Key-value observable.
505 #[unsafe(method(isInputAvailable))]
506 #[unsafe(method_family = none)]
507 pub unsafe fn isInputAvailable(&self) -> bool;
508
509 #[cfg(feature = "AVAudioSessionRoute")]
510 /// DataSource methods are for use with routes that support input or output data source
511 /// selection.
512 ///
513 /// If the attached accessory supports data source selection, the data source properties/methods
514 /// provide for discovery and selection of input and/or output data sources. Note that the
515 /// properties and methods for data source selection below are equivalent to the properties and
516 /// methods on AVAudioSessionPortDescription. The methods below only apply to the currently routed
517 /// ports.
518 ///
519 /// Key-value observable.
520 #[unsafe(method(inputDataSources))]
521 #[unsafe(method_family = none)]
522 pub unsafe fn inputDataSources(
523 &self,
524 ) -> Option<Retained<NSArray<AVAudioSessionDataSourceDescription>>>;
525
526 #[cfg(feature = "AVAudioSessionRoute")]
527 /// Obtain the currently selected input data source. Will be nil if no data sources are available.
528 #[unsafe(method(inputDataSource))]
529 #[unsafe(method_family = none)]
530 pub unsafe fn inputDataSource(
531 &self,
532 ) -> Option<Retained<AVAudioSessionDataSourceDescription>>;
533
534 #[cfg(feature = "AVAudioSessionRoute")]
535 /// Select a new input data source. Setting a nil value will clear the data source preference.
536 #[unsafe(method(setInputDataSource:error:_))]
537 #[unsafe(method_family = none)]
538 pub unsafe fn setInputDataSource_error(
539 &self,
540 data_source: Option<&AVAudioSessionDataSourceDescription>,
541 ) -> Result<(), Retained<NSError>>;
542
543 #[cfg(feature = "AVAudioSessionRoute")]
544 /// See inputDataSources for background. Key-value observable.
545 #[unsafe(method(outputDataSources))]
546 #[unsafe(method_family = none)]
547 pub unsafe fn outputDataSources(
548 &self,
549 ) -> Option<Retained<NSArray<AVAudioSessionDataSourceDescription>>>;
550
551 #[cfg(feature = "AVAudioSessionRoute")]
552 /// Obtain the currently selected output data source. Will be nil if no data sources are available.
553 #[unsafe(method(outputDataSource))]
554 #[unsafe(method_family = none)]
555 pub unsafe fn outputDataSource(
556 &self,
557 ) -> Option<Retained<AVAudioSessionDataSourceDescription>>;
558
559 #[cfg(feature = "AVAudioSessionRoute")]
560 /// Select a new output data source. Setting a nil value will clear the data source preference.
561 #[unsafe(method(setOutputDataSource:error:_))]
562 #[unsafe(method_family = none)]
563 pub unsafe fn setOutputDataSource_error(
564 &self,
565 data_source: Option<&AVAudioSessionDataSourceDescription>,
566 ) -> Result<(), Retained<NSError>>;
567
568 /// The current hardware sample rate. Is key-value observable (starting iOS 18.0).
569 #[unsafe(method(sampleRate))]
570 #[unsafe(method_family = none)]
571 pub unsafe fn sampleRate(&self) -> c_double;
572
573 /// The current number of hardware input channels. Is key-value observable.
574 #[unsafe(method(inputNumberOfChannels))]
575 #[unsafe(method_family = none)]
576 pub unsafe fn inputNumberOfChannels(&self) -> NSInteger;
577
578 /// The current number of hardware output channels. Is key-value observable.
579 #[unsafe(method(outputNumberOfChannels))]
580 #[unsafe(method_family = none)]
581 pub unsafe fn outputNumberOfChannels(&self) -> NSInteger;
582
583 /// The current hardware input latency in seconds.
584 #[unsafe(method(inputLatency))]
585 #[unsafe(method_family = none)]
586 pub unsafe fn inputLatency(&self) -> NSTimeInterval;
587
588 /// The current hardware output latency in seconds.
589 #[unsafe(method(outputLatency))]
590 #[unsafe(method_family = none)]
591 pub unsafe fn outputLatency(&self) -> NSTimeInterval;
592
593 /// The current hardware IO buffer duration in seconds. Is key-value observable.
594 #[unsafe(method(IOBufferDuration))]
595 #[unsafe(method_family = none)]
596 pub unsafe fn IOBufferDuration(&self) -> NSTimeInterval;
597
598 #[cfg(feature = "AVAudioChannelLayout")]
599 /// Get an array of channel layouts that the current route supports.
600 /// This property is only supported when the output is routed to ports of type AVAudioSessionPortCarAudio or AVAudioSessionPortAirPlay
601 /// Otherwise, an empty array will be returned. Note that this will return an empty array if session is inactive.
602 /// Clients should listen to AVAudioSessionRenderingCapabilitiesChangeNotification to be notified when this changes.
603 #[unsafe(method(supportedOutputChannelLayouts))]
604 #[unsafe(method_family = none)]
605 pub unsafe fn supportedOutputChannelLayouts(
606 &self,
607 ) -> Retained<NSArray<AVAudioChannelLayout>>;
608 );
609}
610
611/// Observation.
612impl AVAudioSession {
613 extern_methods!(
614 /// True when another application is playing audio.
615 ///
616 /// Note: As of iOS 8.0, Apple recommends that most applications use
617 /// secondaryAudioShouldBeSilencedHint instead of this property. The otherAudioPlaying property
618 /// will be true if any other audio (including audio from an app using
619 /// AVAudioSessionCategoryAmbient) is playing, whereas the secondaryAudioShouldBeSilencedHint
620 /// property is more restrictive in its consideration of whether primary audio from another
621 /// application is playing.
622 #[unsafe(method(isOtherAudioPlaying))]
623 #[unsafe(method_family = none)]
624 pub unsafe fn isOtherAudioPlaying(&self) -> bool;
625
626 /// True when another application with a non-mixable audio session is playing audio.
627 ///
628 /// Applications may use this property as a hint to silence audio that is secondary to the
629 /// functionality of the application. For example, a game app using AVAudioSessionCategoryAmbient
630 /// may use this property to decide to mute its soundtrack while leaving its sound effects unmuted.
631 /// Note: This property is closely related to AVAudioSessionSilenceSecondaryAudioHintNotification.
632 #[unsafe(method(secondaryAudioShouldBeSilencedHint))]
633 #[unsafe(method_family = none)]
634 pub unsafe fn secondaryAudioShouldBeSilencedHint(&self) -> bool;
635
636 /// The current output volume. Value in range [0.0, 1.0]. Is key-value observable.
637 #[unsafe(method(outputVolume))]
638 #[unsafe(method_family = none)]
639 pub unsafe fn outputVolume(&self) -> c_float;
640
641 #[cfg(feature = "AVAudioSessionTypes")]
642 /// The prompt style is a hint to sessions using AVAudioSessionModeVoicePrompt to alter the type of
643 /// prompts they issue in response to other audio activity on the system, such as Siri and phone
644 /// calls. This property is key-value observable.
645 #[unsafe(method(promptStyle))]
646 #[unsafe(method_family = none)]
647 pub unsafe fn promptStyle(&self) -> AVAudioSessionPromptStyle;
648 );
649}
650
651/// RoutingConfiguration.
652impl AVAudioSession {
653 extern_methods!(
654 #[cfg(feature = "AVAudioSessionRoute")]
655 /// Get the set of input ports that are available for routing.
656 ///
657 /// Note that this property only applies to the session's current category and mode. For
658 /// example, if the session's current category is AVAudioSessionCategoryPlayback, there will be
659 /// no available inputs.
660 ///
661 /// On iOS, clients can listen to AVAudioSessionAvailableInputsChangeNotification to
662 /// be notified when this changes.
663 #[unsafe(method(availableInputs))]
664 #[unsafe(method_family = none)]
665 pub unsafe fn availableInputs(
666 &self,
667 ) -> Option<Retained<NSArray<AVAudioSessionPortDescription>>>;
668
669 #[cfg(feature = "AVAudioSessionRoute")]
670 /// A description of the current route, consisting of zero or more input ports and zero or more
671 /// output ports
672 #[unsafe(method(currentRoute))]
673 #[unsafe(method_family = none)]
674 pub unsafe fn currentRoute(&self) -> Retained<AVAudioSessionRouteDescription>;
675
676 #[cfg(feature = "AVAudioSessionTypes")]
677 /// Controls whether audio input and output are aggregated. Only valid in combination with
678 /// AVAudioSessionCategoryPlayAndRecord or AVAudioSessionCategoryMultiRoute.
679 ///
680 /// See the AVAudioSessionIOType documentation for a more detailed explanation of why a client may
681 /// want to change the IO type.
682 #[unsafe(method(setAggregatedIOPreference:error:_))]
683 #[unsafe(method_family = none)]
684 pub unsafe fn setAggregatedIOPreference_error(
685 &self,
686 in_io_type: AVAudioSessionIOType,
687 ) -> Result<(), Retained<NSError>>;
688
689 /// Set YES to inform the system if the app can supply multichannel audio content.
690 /// Default value is NO. This property is intended to be used by 'Now Playing' applications.
691 /// See https://developer.apple.com/documentation/mediaplayer/becoming_a_now_playable_app for more information
692 /// about what it means to be a 'Now Playing' application. Typically 'Now Playing' applications will also use
693 /// AVAudioSessionRouteSharingPolicyLongFormAudio or AVAudioSessionRouteSharingPolicyLongFormVideo.
694 #[unsafe(method(setSupportsMultichannelContent:error:_))]
695 #[unsafe(method_family = none)]
696 pub unsafe fn setSupportsMultichannelContent_error(
697 &self,
698 in_value: bool,
699 ) -> Result<(), Retained<NSError>>;
700
701 #[unsafe(method(supportsMultichannelContent))]
702 #[unsafe(method_family = none)]
703 pub unsafe fn supportsMultichannelContent(&self) -> bool;
704
705 /// Use this method to opt in or opt out of interruption on route disconnect policy.
706 ///
707 /// As described in the Audio Session Programming Guide, most media playback apps are expected
708 /// to pause playback if the route change reason is AVAudioSessionRouteChangeReasonOldDeviceUnavailable.
709 ///
710 /// Starting in iOS 17, by default Now Playing sessions will be interrupted if they are active
711 /// when a route change occurs because of a disconnect event. All other sessions will not be
712 /// interrupted due to a disconnect event.
713 #[unsafe(method(setPrefersInterruptionOnRouteDisconnect:error:_))]
714 #[unsafe(method_family = none)]
715 pub unsafe fn setPrefersInterruptionOnRouteDisconnect_error(
716 &self,
717 in_value: bool,
718 ) -> Result<(), Retained<NSError>>;
719
720 /// Indicates if session will be interrupted on route disconnect.
721 #[unsafe(method(prefersInterruptionOnRouteDisconnect))]
722 #[unsafe(method_family = none)]
723 pub unsafe fn prefersInterruptionOnRouteDisconnect(&self) -> bool;
724 );
725}
726
727/// MicrophoneInjection.
728impl AVAudioSession {
729 extern_methods!(
730 #[cfg(feature = "AVAudioSessionTypes")]
731 /// Set the preferred form of audio injection into another app's input stream
732 /// See AVAudioSessionMicrophoneInjectionMode for available modes
733 #[unsafe(method(setPreferredMicrophoneInjectionMode:error:_))]
734 #[unsafe(method_family = none)]
735 pub unsafe fn setPreferredMicrophoneInjectionMode_error(
736 &self,
737 in_value: AVAudioSessionMicrophoneInjectionMode,
738 ) -> Result<(), Retained<NSError>>;
739
740 #[cfg(feature = "AVAudioSessionTypes")]
741 #[unsafe(method(preferredMicrophoneInjectionMode))]
742 #[unsafe(method_family = none)]
743 pub unsafe fn preferredMicrophoneInjectionMode(
744 &self,
745 ) -> AVAudioSessionMicrophoneInjectionMode;
746
747 /// Indicates if microphone injection is available.
748 /// Observe AVAudioSessionMicrophoneInjectionCapabilitiesChangeNotification for changes to this property
749 #[unsafe(method(isMicrophoneInjectionAvailable))]
750 #[unsafe(method_family = none)]
751 pub unsafe fn isMicrophoneInjectionAvailable(&self) -> bool;
752 );
753}