internal static void ValidateAudioCodec(RecorderAudioCodec codec) { if (GetSupportedAudioCodecs().Contains(codec) == false) { throw new NotSupportedException($"{codec.ToString()} is not supported."); } }
/// <summary> /// Sets the audio codec and the file format for recording. /// </summary> /// <param name="audioCodec">The codec for audio encoding.</param> /// <param name="fileFormat">The format of result file.</param> /// <exception cref="NotSupportedException"> /// <paramref name="audioCodec"/> is not supported.<br/> /// -or-<br/> /// <paramref name="fileFormat"/> is not supported with the specified audio codec. /// </exception> /// <exception cref="ArgumentException"> /// <paramref name="audioCodec"/> is not valid.<br/> /// -or-<br/> /// <paramref name="fileFormat"/> is not valid. /// </exception> /// <exception cref="ArgumentOutOfRangeException"> /// <paramref name="audioCodec"/> is <see cref="RecorderAudioCodec.None"/> /// </exception> /// <seealso cref="Recorder.GetSupportedAudioCodecs"/> /// <seealso cref="Recorder.GetSupportedFileFormats"/> /// <seealso cref="RecorderExtensions.GetSupportedFileFormats(RecorderAudioCodec)"/> /// <seealso cref="Recorder.Start(string)"/> /// <since_tizen> 4 </since_tizen> public void SetFormatAndCodec(RecorderAudioCodec audioCodec, RecorderFileFormat fileFormat) { ThrowIfCodecAndFormatNotValid(audioCodec, fileFormat); AudioCodec = audioCodec; FileFormat = fileFormat; }
/// <summary> /// Initialize a new instance of the <see cref="StreamRecorderAudioOptions"/> class with the specified /// codec, sample rate, bit rate, and channel value. /// </summary> /// <param name="codec">The <see cref="RecorderAudioCodec"/> for encoding audio stream.</param> /// <param name="sampleRate">The sample rate for encoding audio stream.</param> /// <param name="bitRate">The bit rate for encoding audio stream.</param> /// <param name="channels">The number of channels for encoding audio stream.</param> /// <exception cref="ArgumentException"><paramref name="codec"/> is not valid.</exception> /// <exception cref="ArgumentOutOfRangeException"> /// <paramref name="sampleRate"/> is less than zero.<br/> /// -or-<br/> /// <paramref name="bitRate"/> is less than or equal to zero.<br/> /// -or-<br/> /// <paramref name="channels"/> is less than or equal to zero. /// </exception> /// <since_tizen> 4 </since_tizen> public StreamRecorderAudioOptions(RecorderAudioCodec codec, int sampleRate, int bitRate, int channels) { Codec = codec; SampleRate = sampleRate; BitRate = bitRate; Channels = channels; }
internal static void ThrowIfFormatNotSupported(this RecorderAudioCodec audioCodec, RecorderFileFormat fileFormat) { ValidationUtil.ValidateEnum(typeof(RecorderFileFormat), fileFormat, nameof(fileFormat)); if (audioCodec.GetSupportedFileFormats().Contains(fileFormat) == false) { throw new NotSupportedException($"{audioCodec} does not support {fileFormat}."); } }
private static void ThrowIfCodecAndFormatNotValid(RecorderAudioCodec audioCodec, RecorderFileFormat fileFormat) { if (audioCodec == RecorderAudioCodec.None) { throw new ArgumentOutOfRangeException(nameof(audioCodec), "RecorderAudioCodec.None is only available with VideoRecorder."); } audioCodec.ThrowIfFormatNotSupported(fileFormat); }
private static void ThrowIfCodecAndFormatNotValid(RecorderVideoCodec videoCodec, RecorderAudioCodec audioCodec, RecorderFileFormat fileFormat) { videoCodec.ThrowIfFormatNotSupported(fileFormat); if (audioCodec != RecorderAudioCodec.None) { audioCodec.ThrowIfFormatNotSupported(fileFormat); } }
internal static StreamRecorderAudioCodec ToStreamRecorderEnum(this RecorderAudioCodec value) { switch (value) { case RecorderAudioCodec.Aac: return(StreamRecorderAudioCodec.Aac); case RecorderAudioCodec.Amr: return(StreamRecorderAudioCodec.Amr); case RecorderAudioCodec.Pcm: return(StreamRecorderAudioCodec.Pcm); } throw new NotSupportedException($"{value.ToString()} is not supported."); }
/// <summary> /// Returns supported file formats for a <see cref="RecorderAudioCodec"/>. /// </summary> /// <returns>An IEnumerable of <see cref="RecorderFileFormat"/> representing the supported file formats.</returns> /// <param name="audioCodec">The <see cref="RecorderAudioCodec"/>.</param> /// <exception cref="ArgumentException"><paramref name="audioCodec"/> is invalid.</exception> /// <since_tizen> 4 </since_tizen> public static IEnumerable <RecorderFileFormat> GetSupportedFileFormats(this RecorderAudioCodec audioCodec) { ValidationUtil.ValidateEnum(typeof(RecorderAudioCodec), audioCodec, nameof(audioCodec)); switch (audioCodec) { case RecorderAudioCodec.Amr: yield return(RecorderFileFormat.ThreeGp); yield return(RecorderFileFormat.Amr); break; case RecorderAudioCodec.Mp3: yield return(RecorderFileFormat.Mp4); yield return(RecorderFileFormat.M2ts); break; case RecorderAudioCodec.Aac: yield return(RecorderFileFormat.ThreeGp); yield return(RecorderFileFormat.Mp4); yield return(RecorderFileFormat.M2ts); yield return(RecorderFileFormat.Adts); break; case RecorderAudioCodec.Vorbis: yield return(RecorderFileFormat.Ogg); break; case RecorderAudioCodec.Pcm: yield return(RecorderFileFormat.Wav); break; } }
/// <summary> /// Initializes a new instance of the <see cref="AudioRecorder"/> class with the specified audio codec and file format. /// </summary> /// <param name="audioCodec">The codec for audio encoding.</param> /// <param name="fileFormat">The format of result file.</param> /// <feature>http://tizen.org/feature/microphone</feature> /// <exception cref="InvalidOperationException">An internal error occurred.</exception> /// <exception cref="NotSupportedException"> /// A required feature is not supported.<br/> /// -or-<br/> /// <paramref name="audioCodec"/> is not supported.<br/> /// -or-<br/> /// <paramref name="fileFormat"/> is not supported with the specified audio codec. /// </exception> /// <exception cref="ArgumentException"> /// <paramref name="audioCodec"/> is not valid.<br/> /// -or-<br/> /// <paramref name="fileFormat"/> is not valid. /// </exception> /// <exception cref="ArgumentOutOfRangeException"> /// <paramref name="audioCodec"/> is <see cref="RecorderAudioCodec.None"/> /// </exception> /// <seealso cref="Recorder.GetSupportedAudioCodecs"/> /// <seealso cref="Recorder.GetSupportedFileFormats"/> /// <seealso cref="RecorderExtensions.GetSupportedFileFormats(RecorderAudioCodec)"/> /// <seealso cref="SetFormatAndCodec(RecorderAudioCodec, RecorderFileFormat)"/> /// <since_tizen> 4 </since_tizen> public AudioRecorder(RecorderAudioCodec audioCodec, RecorderFileFormat fileFormat) : base(CreateHandle()) { SetFormatAndCodec(audioCodec, fileFormat); }
/// <summary> /// Initializes a new instance of the <see cref="VideoRecorder"/> class with the specified /// camera, video codec, audio codec, and file format. /// </summary> /// <remarks> /// If the state of <see cref="Camera"/> is <see cref="CameraState.Created"/>, /// the <see cref="CameraSettings.PreviewPixelFormat"/> will be changed to the recommended format for recording.<br/> /// <br/> /// The initial state of the Recorder will be <see cref="RecorderState.Ready"/> /// if the state of <see cref="Camera"/> is <see cref="CameraState.Preview"/> or <see cref="CameraState.Captured"/>. /// </remarks> /// <param name="camera">The camera object.</param> /// <param name="videoCodec">The codec for video encoding.</param> /// <param name="audioCodec">The codec for audio encoding.</param> /// <param name="fileFormat">The format of result file.</param> /// <feature>http://tizen.org/feature/camera</feature> /// <exception cref="InvalidOperationException">An internal error occurred.</exception> /// <exception cref="NotSupportedException"> /// A required feature is not supported.<br/> /// -or-<br/> /// <paramref name="videoCodec"/> is not supported.<br/> /// -or-<br/> /// <paramref name="audioCodec"/> is not supported.<br/> /// -or-<br/> /// <paramref name="fileFormat"/> is not supported with the specified video codec.<br/> /// -or-<br/> /// <paramref name="fileFormat"/> is not supported with the specified audio codec. /// </exception> /// <exception cref="ArgumentException"> /// <paramref name="videoCodec"/> is not valid.<br/> /// -or-<br/> /// <paramref name="audioCodec"/> is not valid.<br/> /// -or-<br/> /// <paramref name="fileFormat"/> is not valid. /// </exception> /// <exception cref="ObjectDisposedException"><paramref name="camera"/> has been disposed of.</exception> /// <exception cref="ArgumentNullException"><paramref name="camera"/> is null.</exception> /// <seealso cref="Recorder.GetSupportedAudioCodecs"/> /// <seealso cref="GetSupportedVideoCodecs"/> /// <seealso cref="Recorder.GetSupportedFileFormats"/> /// <seealso cref="RecorderExtensions.GetSupportedFileFormats(RecorderAudioCodec)"/> /// <seealso cref="RecorderExtensions.GetSupportedFileFormats(RecorderVideoCodec)"/> /// <seealso cref="SetFormatAndCodec(RecorderVideoCodec, RecorderFileFormat)"/> /// <seealso cref="SetFormatAndCodec(RecorderVideoCodec, RecorderAudioCodec, RecorderFileFormat)"/> /// <since_tizen> 4 </since_tizen> public VideoRecorder(Camera camera, RecorderVideoCodec videoCodec, RecorderAudioCodec audioCodec, RecorderFileFormat fileFormat) : base(CreateHandle(camera)) { SetFormatAndCodec(videoCodec, RecorderAudioCodec.None, fileFormat); }
public AudioRecordService() { _state = AudioRecordState.Init; numbering = 0; // Create an audio recorder if (_recorder == null) { // find out the available audio codec and file format RecorderAudioCodec AudioCodec = RecorderAudioCodec.Amr; foreach (RecorderAudioCodec codec in Recorder.GetSupportedAudioCodecs()) { //Console.WriteLine("RecorderAudioCodec : " + codec); foreach (RecorderFileFormat format in codec.GetSupportedFileFormats()) { //Console.WriteLine(" RecorderFileFormat : " + format); if (format == AudioFileFormat) { AudioCodec = codec; break; } } } // Console.WriteLine("+++ Selected AudioCodec : " + AudioCodec + " Format : " + AudioFileFormat); // 2017-12-08: Todo need to roll back.. //_recorder = new AudioRecorder(AudioCodec, AudioFileFormat); //RecorderAudioCodec audioCodec, RecorderFileFormat fileFormat _recorder = new AudioRecorder(AudioCodec, AudioFileFormat); _recorder.StateChanged += AudioRecorder_StateChanged; _recorder.RecordingStatusChanged += AudioRecorder_RecordingStatusChanged; _recorder.RecordingLimitReached += AudioRecorder_RecordingLimitReached; _recorder.ErrorOccurred += AudioRecorder_ErrorOccurred; AudioRecorder.DeviceStateChanged += AudioRecorder_DeviceStateChanged; _recorder.Interrupting += AudioRecorder_Interrupting; //audioRecorder.ApplyAudioStreamPolicy(new AudioStreamPolicy(AudioStreamType.Media)); //audioRecorder.AudioChannels = 2; _recorder.AudioDevice = RecorderAudioDevice.Mic; _recorder.AudioBitRate = 128000; _recorder.AudioSampleRate = AMC_CODEC_AUDIO_SAMPLE_RATE; if (_recorder.State != RecorderState.Idle) { Console.WriteLine("AudioRecordService() : Invalid State (" + _recorder.State + ")" + "...may retry?"); } _recorder.Prepare(); if (_recorder.State != RecorderState.Ready) { Console.WriteLine("AudioRecordService() : Invalid State (" + _recorder.State + ")" + "...may retry?"); } try { SystemStorage internalStorage = StorageManager.Storages.Where(s => s.StorageType == StorageArea.Internal).FirstOrDefault(); var SoundsDir = internalStorage.GetAbsolutePath(DirectoryType.Sounds); audioStoragePath = Path.Combine(SoundsDir, "DotnetVoiceMemo"); // Create directory to save audio files Directory.CreateDirectory(audioStoragePath); } catch (Exception e) { Toast.DisplayText(e.Message + " - DotnetVoiceMemo directory creation failed."); } } }
/// <summary> /// Initialize a new instance of the <see cref="StreamRecorderAudioOptions"/> class with the specified codec. /// </summary> /// <param name="codec">The <see cref="RecorderAudioCodec"/> for encoding audio stream.</param> /// <remarks> /// <see cref="SampleRate"/>, <see cref="BitRate"/> and <see cref="Channels"/> will be set as default. /// </remarks> /// <exception cref="ArgumentException"><paramref name="codec"/> is not valid.</exception> /// <since_tizen> 4 </since_tizen> public StreamRecorderAudioOptions(RecorderAudioCodec codec) : this(codec, DefaultSampleRate, DefaultBitRate, DefaultChannels) { }
internal static extern RecorderErrorCode SetAudioEncoder(RecorderHandle handle, RecorderAudioCodec codec);