|
31 | 31 | #nullable enable |
32 | 32 |
|
33 | 33 | namespace AVFoundation { |
34 | | -#if !TVOS |
35 | 34 | public partial class AVAudioRecorder { |
36 | | - AVAudioRecorder (NSUrl url, AudioSettings settings, out NSError error) |
37 | | - { |
38 | | - // We use this method because it allows us to out NSError but, as a side effect, it is possible for the handle to be null and we will need to check this manually (on the Create method). |
39 | | - Handle = InitWithUrl (url, settings.Dictionary, out error); |
40 | | - } |
41 | | - |
42 | | - AVAudioRecorder (NSUrl url, AVAudioFormat format, out NSError error) |
43 | | - { |
44 | | - // We use this method because it allows us to out NSError but, as a side effect, it is possible for the handle to be null and we will need to check this manually (on the Create method). |
45 | | - Handle = InitWithUrl (url, format, out error); |
46 | | - } |
47 | | - |
48 | | - /// <param name="url">To be added.</param> |
49 | | - /// <param name="settings">To be added.</param> |
50 | | - /// <param name="error">To be added.</param> |
51 | | - /// <summary>Static factory method for creating an <see cref="T:AVFoundation.AVAudioRecorder" />.</summary> |
52 | | - /// <returns>To be added.</returns> |
53 | | - /// <remarks>To be added.</remarks> |
| 35 | + /// <summary>Create a new <see cref="AVAudioRecorder" /> instance.</summary> |
| 36 | + /// <param name="url">The url for the new <see cref="AVAudioRecorder" /> instance.</param> |
| 37 | + /// <param name="settings">The settings for the new <see cref="AVAudioRecorder" /> instance.</param> |
| 38 | + /// <param name="error">Returns the error if creating a new <see cref="AVAudioRecorder" /> instance fails.</param> |
| 39 | + /// <returns>A newly created <see cref="AVAudioRecorder" /> instance if successful, null otherwise.</returns> |
54 | 40 | public static AVAudioRecorder? Create (NSUrl url, AudioSettings settings, out NSError? error) |
55 | 41 | { |
56 | 42 | if (settings is null) |
57 | 43 | ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (settings)); |
58 | | - error = null; |
59 | | - try { |
60 | | - AVAudioRecorder r = new AVAudioRecorder (url, settings, out error); |
61 | | - if (r.Handle == IntPtr.Zero) |
62 | | - return null; |
63 | | - |
64 | | - return r; |
65 | | - } catch { |
| 44 | + var rv = new AVAudioRecorder (NSObjectFlag.Empty); |
| 45 | + rv.InitializeHandle (rv._InitWithUrl (url, settings.Dictionary, out error), string.Empty, false); |
| 46 | + if (rv.Handle == IntPtr.Zero) { |
| 47 | + rv.Dispose (); |
66 | 48 | return null; |
67 | 49 | } |
| 50 | + return rv; |
68 | 51 | } |
69 | 52 |
|
70 | | - /// <param name="url">To be added.</param> |
71 | | - /// <param name="format">To be added.</param> |
72 | | - /// <param name="error">To be added.</param> |
73 | | - /// <summary>To be added.</summary> |
74 | | - /// <returns>To be added.</returns> |
75 | | - /// <remarks>To be added.</remarks> |
76 | | - [SupportedOSPlatform ("ios")] |
77 | | - [SupportedOSPlatform ("macos")] |
78 | | - [SupportedOSPlatform ("maccatalyst")] |
79 | | - [UnsupportedOSPlatform ("tvos")] |
| 53 | + /// <summary>Create a new <see cref="AVAudioRecorder" /> instance.</summary> |
| 54 | + /// <param name="url">The url for the new <see cref="AVAudioRecorder" /> instance.</param> |
| 55 | + /// <param name="format">The format for the new <see cref="AVAudioRecorder" /> instance.</param> |
| 56 | + /// <param name="error">Returns the error if creating a new <see cref="AVAudioRecorder" /> instance fails.</param> |
| 57 | + /// <returns>A newly created <see cref="AVAudioRecorder" /> instance if successful, null otherwise.</returns> |
80 | 58 | public static AVAudioRecorder? Create (NSUrl url, AVAudioFormat? format, out NSError? error) |
81 | 59 | { |
82 | 60 | if (format is null) |
83 | 61 | ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (format)); |
84 | | - error = null; |
85 | | - try { |
86 | | - AVAudioRecorder r = new AVAudioRecorder (url, format, out error); |
87 | | - if (r.Handle == IntPtr.Zero) |
88 | | - return null; |
89 | | - |
90 | | - return r; |
91 | | - } catch { |
| 62 | + var rv = new AVAudioRecorder (NSObjectFlag.Empty); |
| 63 | + rv.InitializeHandle (rv._InitWithUrl (url, format, out error), string.Empty, false); |
| 64 | + if (rv.Handle == IntPtr.Zero) { |
| 65 | + rv.Dispose (); |
92 | 66 | return null; |
93 | 67 | } |
94 | | - } |
95 | | - |
96 | | - internal static AVAudioRecorder? ToUrl (NSUrl url, NSDictionary settings, out NSError? error) |
97 | | - { |
98 | | - return Create (url, new AudioSettings (settings), out error); |
| 68 | + return rv; |
99 | 69 | } |
100 | 70 | } |
101 | | -#endif // !TVOS |
102 | 71 | } |
0 commit comments