Prerequisites
- A working Android quickstart
- The active
NosmaiPreviewView - A writable absolute
.mp4output path
Recording configuration
NosmaiSDK.startRecording(previewView, outputPath, callback) is the public convenience recorder. It does not accept a bitrate/FPS/quality configuration object.
| Setting | Public contract |
|---|---|
| Output | Writable absolute .mp4 path supplied by the app |
| Dimensions | Derived from the processed preview frame; not an independent startRecording argument |
| Video defaults | Target 30 FPS and 4,000,000 bits/second in this native release; actual delivery depends on processing and hardware |
| Maximum duration | App-owned policy; stop and finalize when the limit is reached |
| Audio | Verify the actual output for the chosen path; do not assume the streaming provider's microphone track is recorded |
Begin only after real processed frames arrive, not merely after creating a view. Use stable frame dimensions and even encoder dimensions. On measured lower-tier devices, the SDK can cap the recording's long edge at 1280 pixels to reduce encode load without reducing preview dimensions. A preview's layout size is not a promise of the saved file's resolution.
For a custom codec, fixed bitrate, microphone/audio mixing, or independently controlled output size, consume processed native output with an app-owned encoder; see Custom frame pipelines. Do not import internal recorder classes to configure this convenience API, or assume RTC publishing settings also configure a local recording.
Start recording
NosmaiSDK.startRecording(previewView, outputPath,
new NosmaiSDK.RecordingCallback() {
@Override
public void onStarted(boolean success, String error) {
if (!success) {
Log.e("Nosmai", "Recording did not start: " + error);
}
}
});
Disable duplicate start requests until onStarted returns.
Stop and finalize the MP4
NosmaiSDK.stopRecording(new NosmaiSDK.RecordingCallback() {
@Override
public void onCompleted(String path, boolean success, String error) {
if (success) {
Log.i("Nosmai", "Video ready at " + path);
} else {
Log.e("Nosmai", "Recording failed: " + error);
}
}
});
Wait for onCompleted before opening, sharing, or scanning the file. The callback path is the final result; handle success == false even if starting previously succeeded. Retain the preview and recording owner until finalization finishes. Dispatch UI changes to the main thread rather than assuming every completion is a UI callback.
Lifecycle rule
Stop and finalize recording before switching camera, pausing the activity, or destroying the preview. On measured lower-tier devices the SDK can reduce only the recording resolution to protect frame rate; the live preview remains at its configured size.
Keep start, stop, and any duration-limit timer under one serialized state machine. Cancel the timer when recording ends. A timer requesting stop does not mean that the file is already finalized.
Verify it worked
Record a short clip with a visible effect, wait for onCompleted, and play the returned MP4. Confirm its orientation, effect output, video duration, and audio.
Common errors
| Symptom | Cause | Fix |
|---|---|---|
| Recording does not start | The preview is not ready or another start is in progress | Wait for camera startup and guard the record button |
| The file cannot be opened | The app used it before onCompleted | Wait for finalization and use a writable absolute .mp4 path |