2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 using Native = Interop.Recorder;
19 using NativeHandle = Interop.RecorderHandle;
21 namespace Tizen.Multimedia
24 /// Provides the ability to control audio recording.
26 public class AudioRecorder : Recorder
28 private static NativeHandle CreateHandle()
30 Native.Create(out var handle).ThrowIfError("Failed to create Audio recorder");
35 private static void ThrowIfCodecAndFormatNotValid(RecorderAudioCodec audioCodec, RecorderFileFormat fileFormat)
37 if (audioCodec == RecorderAudioCodec.None)
39 throw new ArgumentOutOfRangeException(nameof(audioCodec),
40 "RecorderAudioCodec.None is only available with VideoRecorder.");
43 audioCodec.ThrowIfFormatNotSupported(fileFormat);
47 /// Initializes a new instance of the <see cref="AudioRecorder"/> class with the specified audio codec and file format.
49 /// <param name="audioCodec">The codec for audio encoding.</param>
50 /// <param name="fileFormat">The format of result file.</param>
51 /// <feature>http://tizen.org/feature/microphone</feature>
52 /// <exception cref="InvalidOperationException">An internal error occurred.</exception>
53 /// <exception cref="NotSupportedException">
54 /// A required feature is not supported.<br/>
56 /// <paramref name="audioCodec"/> is not supported.<br/>
58 /// <paramref name="fileFormat"/> is not supported with the specified audio codec.
60 /// <exception cref="ArgumentException">
61 /// <paramref name="audioCodec"/> is not valid.<br/>
63 /// <paramref name="fileFormat"/> is not valid.
65 /// <exception cref="ArgumentOutOfRangeException">
66 /// <paramref name="audioCodec"/> is <see cref="RecorderAudioCodec.None"/>
68 /// <seealso cref="Recorder.GetSupportedAudioCodecs"/>
69 /// <seealso cref="Recorder.GetSupportedFileFormats"/>
70 /// <seealso cref="RecorderExtensions.GetSupportedFileFormats(RecorderAudioCodec)"/>
71 /// <seealso cref="SetFormatAndCodec(RecorderAudioCodec, RecorderFileFormat)"/>
72 public AudioRecorder(RecorderAudioCodec audioCodec, RecorderFileFormat fileFormat) : base(CreateHandle())
74 SetFormatAndCodec(audioCodec, fileFormat);
78 /// Sets the audio codec and the file format for recording.
80 /// <param name="audioCodec">The codec for audio encoding.</param>
81 /// <param name="fileFormat">The format of result file.</param>
82 /// <exception cref="NotSupportedException">
83 /// <paramref name="audioCodec"/> is not supported.<br/>
85 /// <paramref name="fileFormat"/> is not supported with the specified audio codec.
87 /// <exception cref="ArgumentException">
88 /// <paramref name="audioCodec"/> is not valid.<br/>
90 /// <paramref name="fileFormat"/> is not valid.
92 /// <exception cref="ArgumentOutOfRangeException">
93 /// <paramref name="audioCodec"/> is <see cref="RecorderAudioCodec.None"/>
95 /// <seealso cref="Recorder.GetSupportedAudioCodecs"/>
96 /// <seealso cref="Recorder.GetSupportedFileFormats"/>
97 /// <seealso cref="RecorderExtensions.GetSupportedFileFormats(RecorderAudioCodec)"/>
98 /// <seealso cref="Recorder.Start(string)"/>
99 public void SetFormatAndCodec(RecorderAudioCodec audioCodec, RecorderFileFormat fileFormat)
101 ThrowIfCodecAndFormatNotValid(audioCodec, fileFormat);
103 AudioCodec = audioCodec;
104 FileFormat = fileFormat;