Media Recording

You can use basic recorder features, including an audio and video recorder.

The main media recording features include the following:

The following file formats are supported:

  • Video: MP4 and 3GP
  • Audio: M4A and AMR

Valid input sources consist of internal and external microphones and a camera. The used input audio or video source depends on the currently connected audio path and camera module of the device.

During testing, you can use the emulator to imitate audio or video recording, as long as your computer has a proper input source device.

Prerequisites

To enable your application to use the media recording functionality, follow the steps below:

  1. To use the audio and video recorders, the application has to request permission by adding the following privileges to the tizen-manifest.xml file:

    XML
    Copy
    <privileges> <!--Needed for audio and video recorder--> <privilege>http://tizen.org/privilege/recorder</privilege> <!--Needed for video recorder only--> <privilege>http://tizen.org/privilege/camera</privilege> </privileges>
  2. To use the methods and properties of the Tizen.Multimedia.Camera and Tizen.Multimedia.Recorder classes, include the Tizen.Multimedia namespace in your application:

    C#
    Copy
    using Tizen.Multimedia;

Prepare the audio recorder

To prepare the audio recorder, follow the steps below:

  1. Create an instance of the Tizen.Multimedia.AudioRecorder class, and pass the audio codec and file format of the recording as parameters.

    The possible audio codec values are defined in the Tizen.Multimedia.RecorderAudioCodec enumeration and the possible file format values in the Tizen.Multimedia.RecorderFileFormat enumeration.

    Set the correct file format based on the audio codec. For example, if you set the codec to RecorderAudioCodec.Aac, set the file format to RecorderFileFormat.ThreeGp:

    C#
    Copy
    AudioRecorder audioRecorder = new AudioRecorder(RecorderAudioCodec.Aac, RecorderFileFormat.ThreeGp);

    The recorder state is set to Idle.

  2. Set various audio recorder settings, such as the file size limit, encoder bitrate, and audio device and sample rate:

    C#
    Copy
    /// Set the maximum file size to 1024 (kB) audioRecorder.SizeLimit = 1024; /// Set the audio encoder bitrate audioRecorder.AudioBitRate = 128000; /// Set the audio device as microphone audioRecorder.AudioDevice = RecorderAudioDevice.Mic; /// Set the audio sample rate audioRecorder.AudioSampleRate = 44100;
    Note

    In the emulator, set the sample rate to 44100 and use stereo audio with the AAC codec, or set the sample rate below 8000 and use mono audio with the AMR codec.

  3. To receive a notification whenever the audio recorder state changes:

    • Register an event handler for the StateChanged event of the Tizen.Multimedia.Recorder class:

      C#
      Copy
      audioRecorder.StateChanged += OnStateChanged;
    • Define the state changed event handler.

      The following example prints the previous and current audio recorder states:

      C#
      Copy
      void OnStateChanged(object sender, RecorderStateChangedEventArgs e) { Tizen.Log.Info(LogTag, $"Previous state = {e.PreviousState }, Current State = {e.CurrentState}"); }
  4. To receive a notification when the audio recorder reaches its recording limit:

    • Register an event handler for the RecordingLimitReached event of the Tizen.Multimedia.Recorder class:

      C#
      Copy
      audioRecorder.RecordingLimitReached += OnRecordingLimitReached;
    • Define the recording limit reached event handler.

      The following example prints the type of the reached recording limit:

      C#
      Copy
      void OnRecordingLimitReached(object sender, RecordingLimitReachedEventArgs e) { Tizen.Log.Info(LogTag, $"Limit type = {e.Type}"); }

Record audio

To record audio, follow the steps below:

  1. Prepare the audio recorder by calling the Prepare() method of the Tizen.Multimedia.Recorder class:

    C#
    Copy
    audioRecorder.Prepare();

    The audio recorder state changes to Ready.

  2. Start recording audio by using the Start() method. Based on the file format you have set for the recorder, define an applicable file name and pass the full path with the file name as a parameter to the method:

    C#
    Copy
    audioRecorder.Start(savePath);

    If the target file path and name have been set to an existing file, the existing file is replaced with a new file.

    The audio recorder state changes to Recording.

  3. To pause and resume recording:

    • Pause the recording using the Pause() method:

      C#
      Copy
      audioRecorder.Pause();

      The audio recorder state changes to Paused.

    • Resume the recording using the Resume() method:

      C#
      Copy
      audioRecorder.Resume();

      The audio recorder state changes to Recording.

  4. To stop recording:

    • To stop the recording and save the recorded data, use the Commit() method:

      C#
      Copy
      audioRecorder.Commit();
    • To stop the recording and discard the recorded data, use the Cancel() method:

      C#
      Copy
      audioRecorder.Cancel();

      The audio recorder state changes to Ready.

  5. After you have finished recording, reset the audio recorder using the Unprepare() method and deregister all recorder event handlers:

    C#
    Copy
    /// Reset the recorder audioRecorder.Unprepare(); /// Deregister event handlers audioRecorder -= OnStateChanged; audioRecorder -= OnRecordingLimitReached;

    The audio recorder state changes to Idle.

Prepare the video recorder

To initialize the video recorder for use, follow the steps below:

  1. Create an instance of the Tizen.Multimedia.Camera class:

    C#
    Copy
    var camera = new Camera(CameraDevice.Rear);
  2. To set the display on which the video is recorded, use the Display property of the Tizen.Multimedia.Camera class.

    For example, to set the display on a Xamarin-based application, first create an instance of the custom renderer (For example, VideoView()) based on VisualElementRenderer class, cast it to an instance of the Tizen.Multimedia.MediaView class, and finally set that instance as the Display property:

    C#
    Copy
    var mediaView = new VideoView(); mediaView.NativeViewCreated += (s, e) => { camera.Display = new Display((Tizen.Multimedia.MediaView)(s as VideoView).NativeView); };
  3. Check which video codecs and file formats the device supports:

    C#
    Copy
    var videoCodec = VideoRecorder.GetSupportedVideoCodecs().FirstOrDefault(); var fileFormat = VideoRecorder.GetSupportedFileFormats().FirstOrDefault();
  4. Create an instance of the Tizen.Multimedia.VideoRecorder class by passing the Tizen.Multimedia.Camera instance, and the video codec and file format of the recording to the class constructor.

    Make sure the file format matches the video codec:

    C#
    Copy
    var videoRecorder = new VideoRecorder(camera, videoCodec, fileFormat);

    The recorder state is set to Idle.

  5. Set various video recorder settings, such as the file size limit, video/audio encoder bitrate, video motion rate, audio sample rate, and resolution:

    C#
    Copy
    /// Set the maximum file size to 1024 (kB) videoRecorder.SizeLimit = 1024; /// Set the video motion rate videoRecorder.VideoMotionRate = 1; /// Set the video bitrate videoRecorder.VideoBitRate = 288000; /// Set the audio encoder bitrate videoRecorder.AudioBitRate = 128000; /// Set the audio sample rate videoRecorder.AudioSampleRate = 44100;
  6. To receive a notification when the video recorder reaches its recording limit:

    • Register an event handler for the RecordingLimitReached event of the Tizen.Multimedia.Recorder class:

      C#
      Copy
      videoRecorder.RecordingLimitReached += OnRecordingLimitReached;
    • Define the recording limit reached event handler.

      The following example prints the type of the reached recording limit:

      C#
      Copy
      void OnRecordingLimitReached(object sender, RecordingLimitReachedEventArgs e) { Tizen.Log.Info(LogTag, $"Limit type = {e.Type}"); }

      You can add event handlers similarly to other video recorder events, such as the StateChanged and RecordingStatusChanged events of the Tizen.Multimedia.Recorder class.

Record video

To record video, follow the steps below:

  1. Prepare the video recorder by calling the Prepare() method of the Tizen.Multimedia.Recorder class:

    C#
    Copy
    videoRecorder.Prepare();

    The video recorder state changes to Ready.

  2. Start recording video by using the Start() method. Based on the file format you have set for the recorder, define an applicable file name and pass the full path with the file name as a parameter to the method:

    C#
    Copy
    videoRecorder.Start(SavePath);

    If the target file path and name have been set to an existing file, the existing file is replaced with a new file.

    The video recorder state changes to Recording.

  3. To pause and resume recording:

    • Pause the recording using the Pause() method:

      C#
      Copy
      videoRecorder.Pause();

      The video recorder state changes to Paused.

    • Resume the recording using the Resume method:

      C#
      Copy
      videoRecorder.Resume();

      The video recorder state changes to Recording.

  4. To stop recording:

    • To stop the recording and save the recorded data, use the Commit() method:

      C#
      Copy
      videoRecorder.Commit();
    • To stop the recording and discard the recorded data, use the Cancel() method:

      C#
      Copy
      videoRecorder.Cancel();

      The video recorder state changes to Ready.

  5. After you have finished recording, reset the video recorder using Unprepare() method and deregister all recorder event handlers:

    C#
    Copy
    /// Reset the recorder videoRecorder.Unprepare(); /// Deregister event handler videoRecorder.RecordingLimitReached -= OnRecordingLimitReached;

    The video recorder state changes to Idle.

  • Dependencies
    • Tizen 4.0 and Higher
Media Playback
Next Raw Audio Playback and Recording
Submit your feedback to GitHub