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