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