Media Recording
You can use basic recorder features, including an audio and video recorder.
The main media recording features include the following:
-
Recording audio
You can record audio after you have prepared the audio recorder.
-
Recording video
You can record video after you have prepared the video recorder.
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:
-
To use the audio and video recorders, the application has to request permission by adding the following privileges to the
tizen-manifest.xml
file:XMLCopy<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>
-
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#Copyusing Tizen.Multimedia;
Prepare the audio recorder
To prepare the audio recorder, follow the steps below:
-
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 toRecorderFileFormat.ThreeGp
:C#CopyAudioRecorder audioRecorder = new AudioRecorder(RecorderAudioCodec.Aac, RecorderFileFormat.ThreeGp);
The recorder state is set to
Idle
. -
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.
-
To receive a notification whenever the audio recorder state changes:
-
Register an event handler for the
StateChanged
event of theTizen.Multimedia.Recorder
class:C#CopyaudioRecorder.StateChanged += OnStateChanged;
-
Define the state changed event handler.
The following example prints the previous and current audio recorder states:
C#Copyvoid OnStateChanged(object sender, RecorderStateChangedEventArgs e) { Tizen.Log.Info(LogTag, $"Previous state = {e.PreviousState }, Current State = {e.CurrentState}"); }
-
-
To receive a notification when the audio recorder reaches its recording limit:
-
Register an event handler for the
RecordingLimitReached
event of theTizen.Multimedia.Recorder
class:C#CopyaudioRecorder.RecordingLimitReached += OnRecordingLimitReached;
-
Define the recording limit reached event handler.
The following example prints the type of the reached recording limit:
C#Copyvoid OnRecordingLimitReached(object sender, RecordingLimitReachedEventArgs e) { Tizen.Log.Info(LogTag, $"Limit type = {e.Type}"); }
-
Record audio
To record audio, follow the steps below:
-
Prepare the audio recorder by calling the
Prepare()
method of the Tizen.Multimedia.Recorder class:C#CopyaudioRecorder.Prepare();
The audio recorder state changes to
Ready
. -
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#CopyaudioRecorder.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
. -
To pause and resume recording:
-
Pause the recording using the
Pause()
method:C#CopyaudioRecorder.Pause();
The audio recorder state changes to
Paused
. -
Resume the recording using the
Resume()
method:C#CopyaudioRecorder.Resume();
The audio recorder state changes to
Recording
.
-
-
To stop recording:
-
To stop the recording and save the recorded data, use the
Commit()
method:C#CopyaudioRecorder.Commit();
-
To stop the recording and discard the recorded data, use the
Cancel()
method:C#CopyaudioRecorder.Cancel();
The audio recorder state changes to
Ready
.
-
-
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:
-
Create an instance of the Tizen.Multimedia.Camera class:
C#Copyvar camera = new Camera(CameraDevice.Rear);
-
To set the display on which the video is recorded, use the
Display
property of theTizen.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 theDisplay
property:C#Copyvar mediaView = new VideoView(); mediaView.NativeViewCreated += (s, e) => { camera.Display = new Display((Tizen.Multimedia.MediaView)(s as VideoView).NativeView); };
-
Check which video codecs and file formats the device supports:
- To check which video codecs the device supports, use the
GetSupportedVideoCodecs()
method of the Tizen.Multimedia.Recorder class. The possible video codec values are defined in the Tizen.Multimedia.RecorderVideoCodec enumeration. - To check which file formats the device supports, use the
GetSupportedFileFormats()
method of theTizen.Multimedia.Recorder
class. The possible file format values are defined in the Tizen.Multimedia.RecorderFileFormat enumeration.
C#Copyvar videoCodec = VideoRecorder.GetSupportedVideoCodecs().FirstOrDefault(); var fileFormat = VideoRecorder.GetSupportedFileFormats().FirstOrDefault();
- To check which video codecs the device supports, use the
-
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#Copyvar videoRecorder = new VideoRecorder(camera, videoCodec, fileFormat);
The recorder state is set to
Idle
. -
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;
-
To receive a notification when the video recorder reaches its recording limit:
-
Register an event handler for the
RecordingLimitReached
event of theTizen.Multimedia.Recorder
class:C#CopyvideoRecorder.RecordingLimitReached += OnRecordingLimitReached;
-
Define the recording limit reached event handler.
The following example prints the type of the reached recording limit:
C#Copyvoid 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
andRecordingStatusChanged
events of theTizen.Multimedia.Recorder
class.
-
Record video
To record video, follow the steps below:
-
Prepare the video recorder by calling the
Prepare()
method of the Tizen.Multimedia.Recorder class:C#CopyvideoRecorder.Prepare();
The video recorder state changes to
Ready
. -
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#CopyvideoRecorder.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
. -
To pause and resume recording:
-
Pause the recording using the
Pause()
method:C#CopyvideoRecorder.Pause();
The video recorder state changes to
Paused
. -
Resume the recording using the
Resume
method:C#CopyvideoRecorder.Resume();
The video recorder state changes to
Recording
.
-
-
To stop recording:
-
To stop the recording and save the recorded data, use the
Commit()
method:C#CopyvideoRecorder.Commit();
-
To stop the recording and discard the recorded data, use the
Cancel()
method:C#CopyvideoRecorder.Cancel();
The video recorder state changes to
Ready
.
-
-
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
.
Related information
- Dependencies
- Tizen 4.0 and Higher