MediaRecorder

Encodes media from a registered source and writes it to a file.

Register the recorder with a mixer before recording. Attach capture sources and start the mixer before using this example. The output path must be writable by the application.

val recorder = MediaRecorder(context)
mixer.registerOutput(recorder)
val output = java.io.File(context.filesDir, "output.mp4")
recorder.startRecording(output.absolutePath, MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4)
// After capturing the desired media:
recorder.stopRecording()
mixer.unregisterOutput(recorder)

Constructors

Link copied to clipboard
constructor(context: Context)

Properties

Link copied to clipboard

Specifies the audio codec settings.

Link copied to clipboard

A weak reference to the registered media source, or null when detached.

Link copied to clipboard

Whether this recorder is currently recording audio and video.

Link copied to clipboard

Specifies the video codec settings.

Functions

Link copied to clipboard
open override fun append(buffer: MediaBuffer)

Receives a media buffer from the source. Consume or copy its payload before it is reused.

Link copied to clipboard
@RequiresApi(value = 26)
fun startRecording(fd: FileDescriptor, format: Int)

Starts recording to a file descriptor. Requires Android 8.0 (API 26) or later.

fun startRecording(path: String, format: Int)

Starts recording to a file path.

Link copied to clipboard

Stops recording and finalizes the output file.