objc2_avf_audio/generated/
AVAudioRecorder.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    /// An object that records audio data to a file.
12    ///
13    /// See also [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudiorecorder?language=objc)
14    #[unsafe(super(NSObject))]
15    #[derive(Debug, PartialEq, Eq, Hash)]
16    pub struct AVAudioRecorder;
17);
18
19unsafe impl Send for AVAudioRecorder {}
20
21unsafe impl Sync for AVAudioRecorder {}
22
23extern_conformance!(
24    unsafe impl NSObjectProtocol for AVAudioRecorder {}
25);
26
27impl AVAudioRecorder {
28    extern_methods!(
29        /// Init the AudioRecorder with a specified url and settings.
30        ///
31        /// The file type to create can be set through the corresponding settings key. If not set, it will be inferred from the file extension. Will overwrite a file at the specified url if a file exists.
32        ///
33        /// # Safety
34        ///
35        /// `settings` generic should be of the correct type.
36        #[unsafe(method(initWithURL:settings:error:_))]
37        #[unsafe(method_family = init)]
38        pub unsafe fn initWithURL_settings_error(
39            this: Allocated<Self>,
40            url: &NSURL,
41            settings: &NSDictionary<NSString, AnyObject>,
42        ) -> Result<Retained<Self>, Retained<NSError>>;
43
44        #[cfg(feature = "AVAudioFormat")]
45        /// Init the AudioRecorder with a specified url and format.
46        ///
47        /// The file type to create can be set through the corresponding settings key. If not set, it will be inferred from the file extension. Will overwrite a file at the specified url if a file exists.
48        #[unsafe(method(initWithURL:format:error:_))]
49        #[unsafe(method_family = init)]
50        pub unsafe fn initWithURL_format_error(
51            this: Allocated<Self>,
52            url: &NSURL,
53            format: &AVAudioFormat,
54        ) -> Result<Retained<Self>, Retained<NSError>>;
55
56        /// Creates the output file and gets ready to record.
57        ///
58        /// This method is called automatically on record. Returns YES on success and NO on failure.
59        #[unsafe(method(prepareToRecord))]
60        #[unsafe(method_family = none)]
61        pub unsafe fn prepareToRecord(&self) -> bool;
62
63        /// Start or resume recording to file.
64        ///
65        /// Returns YES on success and NO on failure.
66        #[unsafe(method(record))]
67        #[unsafe(method_family = none)]
68        pub unsafe fn record(&self) -> bool;
69
70        /// Start recording at specified time in the future.
71        ///
72        /// Time is an absolute time based on and greater than deviceCurrentTime. Returns YES on success and NO on failure.
73        #[unsafe(method(recordAtTime:))]
74        #[unsafe(method_family = none)]
75        pub unsafe fn recordAtTime(&self, time: NSTimeInterval) -> bool;
76
77        /// Record for a specified duration.
78        ///
79        /// The recorder will stop when it has recorded this length of audio. Returns YES on success and NO on failure.
80        #[unsafe(method(recordForDuration:))]
81        #[unsafe(method_family = none)]
82        pub unsafe fn recordForDuration(&self, duration: NSTimeInterval) -> bool;
83
84        /// Record for a specified duration at a specified time in the future.
85        ///
86        /// Time is an absolute time based on and greater than deviceCurrentTime. Returns YES on success and NO on failure.
87        #[unsafe(method(recordAtTime:forDuration:))]
88        #[unsafe(method_family = none)]
89        pub unsafe fn recordAtTime_forDuration(
90            &self,
91            time: NSTimeInterval,
92            duration: NSTimeInterval,
93        ) -> bool;
94
95        /// Pause recording.
96        #[unsafe(method(pause))]
97        #[unsafe(method_family = none)]
98        pub unsafe fn pause(&self);
99
100        /// Stop recording.
101        ///
102        /// This method also closes the output file.
103        #[unsafe(method(stop))]
104        #[unsafe(method_family = none)]
105        pub unsafe fn stop(&self);
106
107        /// Delete the recorded file.
108        ///
109        /// AudioRecorder must be stopped. Returns YES on success and NO on failure.
110        #[unsafe(method(deleteRecording))]
111        #[unsafe(method_family = none)]
112        pub unsafe fn deleteRecording(&self) -> bool;
113
114        /// Returns YES if the AudioRecorder is currently recording.
115        #[unsafe(method(isRecording))]
116        #[unsafe(method_family = none)]
117        pub unsafe fn isRecording(&self) -> bool;
118
119        /// URL of the recorded file.
120        #[unsafe(method(url))]
121        #[unsafe(method_family = none)]
122        pub unsafe fn url(&self) -> Retained<NSURL>;
123
124        /// A dictionary of settings for the AudioRecorder.
125        ///
126        /// These settings are fully valid only when prepareToRecord has been called. For supported key-value pairs, see https://developer.apple.com/documentation/avfaudio/avaudiorecorder/1388386-initwithurl?language=objc
127        #[unsafe(method(settings))]
128        #[unsafe(method_family = none)]
129        pub unsafe fn settings(&self) -> Retained<NSDictionary<NSString, AnyObject>>;
130
131        #[cfg(feature = "AVAudioFormat")]
132        /// The audio format of the AudioRecorder.
133        ///
134        /// This property is fully valid only when prepareToRecord has been called.
135        #[unsafe(method(format))]
136        #[unsafe(method_family = none)]
137        pub unsafe fn format(&self) -> Retained<AVAudioFormat>;
138
139        /// A delegate object to the AudioRecorder that conforms to the AVAudioRecorderDelegate protocol.
140        #[unsafe(method(delegate))]
141        #[unsafe(method_family = none)]
142        pub unsafe fn delegate(
143            &self,
144        ) -> Option<Retained<ProtocolObject<dyn AVAudioRecorderDelegate>>>;
145
146        /// Setter for [`delegate`][Self::delegate].
147        ///
148        /// This is a [weak property][objc2::topics::weak_property].
149        #[unsafe(method(setDelegate:))]
150        #[unsafe(method_family = none)]
151        pub unsafe fn setDelegate(
152            &self,
153            delegate: Option<&ProtocolObject<dyn AVAudioRecorderDelegate>>,
154        );
155
156        /// Get the current time of the recording.
157        ///
158        /// This method is only vaild while recording.
159        #[unsafe(method(currentTime))]
160        #[unsafe(method_family = none)]
161        pub unsafe fn currentTime(&self) -> NSTimeInterval;
162
163        /// Get the device current time.
164        ///
165        /// This method is always valid.
166        #[unsafe(method(deviceCurrentTime))]
167        #[unsafe(method_family = none)]
168        pub unsafe fn deviceCurrentTime(&self) -> NSTimeInterval;
169
170        /// Turns level metering on or off.
171        ///
172        /// Default is off.
173        #[unsafe(method(isMeteringEnabled))]
174        #[unsafe(method_family = none)]
175        pub unsafe fn isMeteringEnabled(&self) -> bool;
176
177        /// Setter for [`isMeteringEnabled`][Self::isMeteringEnabled].
178        #[unsafe(method(setMeteringEnabled:))]
179        #[unsafe(method_family = none)]
180        pub unsafe fn setMeteringEnabled(&self, metering_enabled: bool);
181
182        /// Call this method to refresh meter values.
183        #[unsafe(method(updateMeters))]
184        #[unsafe(method_family = none)]
185        pub unsafe fn updateMeters(&self);
186
187        /// Returns peak power in decibels for a given channel.
188        #[unsafe(method(peakPowerForChannel:))]
189        #[unsafe(method_family = none)]
190        pub unsafe fn peakPowerForChannel(&self, channel_number: NSUInteger) -> c_float;
191
192        /// Returns average power in decibels for a given channel.
193        #[unsafe(method(averagePowerForChannel:))]
194        #[unsafe(method_family = none)]
195        pub unsafe fn averagePowerForChannel(&self, channel_number: NSUInteger) -> c_float;
196
197        #[cfg(feature = "AVAudioSessionRoute")]
198        /// Array of AVAudioSessionChannelDescription objects
199        ///
200        /// The channels property lets you assign the output to record specific channels as described by AVAudioSessionPortDescription's channels property. This property is nil valued until set. The array must have the same number of channels as returned by the numberOfChannels property.
201        ///
202        /// This property is not atomic.
203        ///
204        /// # Safety
205        ///
206        /// This might not be thread-safe.
207        #[unsafe(method(channelAssignments))]
208        #[unsafe(method_family = none)]
209        pub unsafe fn channelAssignments(
210            &self,
211        ) -> Option<Retained<NSArray<AVAudioSessionChannelDescription>>>;
212
213        #[cfg(feature = "AVAudioSessionRoute")]
214        /// Setter for [`channelAssignments`][Self::channelAssignments].
215        ///
216        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
217        ///
218        /// # Safety
219        ///
220        /// This might not be thread-safe.
221        #[unsafe(method(setChannelAssignments:))]
222        #[unsafe(method_family = none)]
223        pub unsafe fn setChannelAssignments(
224            &self,
225            channel_assignments: Option<&NSArray<AVAudioSessionChannelDescription>>,
226        );
227    );
228}
229
230/// Methods declared on superclass `NSObject`.
231impl AVAudioRecorder {
232    extern_methods!(
233        #[unsafe(method(init))]
234        #[unsafe(method_family = init)]
235        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
236
237        #[unsafe(method(new))]
238        #[unsafe(method_family = new)]
239        pub unsafe fn new() -> Retained<Self>;
240    );
241}
242
243extern_protocol!(
244    /// A protocol for delegates of AVAudioRecorder.
245    ///
246    /// See also [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudiorecorderdelegate?language=objc)
247    pub unsafe trait AVAudioRecorderDelegate: NSObjectProtocol + Send + Sync {
248        /// This callback method is called when a recording has been finished or stopped.
249        ///
250        /// This method is NOT called if the recorder is stopped due to an interruption.
251        #[optional]
252        #[unsafe(method(audioRecorderDidFinishRecording:successfully:))]
253        #[unsafe(method_family = none)]
254        unsafe fn audioRecorderDidFinishRecording_successfully(
255            &self,
256            recorder: &AVAudioRecorder,
257            flag: bool,
258        );
259
260        /// This callback method is called when an error occurs while encoding.
261        ///
262        /// If an error occurs while encoding it will be reported to the delegate.
263        #[optional]
264        #[unsafe(method(audioRecorderEncodeErrorDidOccur:error:))]
265        #[unsafe(method_family = none)]
266        unsafe fn audioRecorderEncodeErrorDidOccur_error(
267            &self,
268            recorder: &AVAudioRecorder,
269            error: Option<&NSError>,
270        );
271    }
272);