Capture Media
This documentation provides guidelines on capturing images and recording videos using the TruVideo Camera SDK. The SDK offers simple methods to integrate camera functionalities into your application.
Prerequisites
Ensure you have integrated the TruVideo Core SDK into your project and completed with the authentication process
Capturing an Image
To capture an image, follow these steps:
Step 1 : Initalize ActivityResultLauncher
with TruvideoSdkCameraConfiguration
public class YourActivity extends AppCompatActivity{
ActivityResultLauncher<TruvideoSdkCameraConfiguration> cameraScreenLauncher;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
cameraScreenLauncher = registerForActivityResult(
new TruvideoSdkCameraContract(),
result -> {
// Handle result
}
);
//...rest of your code
}
}
Step 2 : Get the Camera Information
This function will provide the default configuration of the camera
TruvideoSdkCameraInformation cameraInfo = TruvideoSdkCamera.getInstance().getInformation()
Step 3 : Create new configuration to give to the camera
TruvideoSdkCameraConfiguration configuration = new TruvideoSdkCameraConfiguration(
TruvideoSdkCameraLensFacing.BACK,
TruvideoSdkCameraFlashMode.OFF,
null,
"",
new ArrayList<>(),
null,
new ArrayList<>(),
null,
TruvideoSdkCameraMode.videoAndPicture()
);
Step 4 : Present the camera with the configuration using TruvideoSdkCameraConfiguration
cameraScreenLauncher.launch(configuration)
Finalize :
After completing this steps the function should look like
import com.truvideo.sdk.camera.model.TruvideoSdkCameraConfiguration;
import com.truvideo.sdk.camera.model.TruvideoSdkCameraFlashMode;
import com.truvideo.sdk.camera.model.TruvideoSdkCameraLensFacing;
import com.truvideo.sdk.camera.model.TruvideoSdkCameraMedia;
import com.truvideo.sdk.camera.model.TruvideoSdkCameraMode;
import com.truvideo.sdk.camera.model.TruvideoSdkCameraOrientation;
import com.truvideo.sdk.camera.model.TruvideoSdkCameraResolution;
public class YourActivity extends AppCompatActivity{
ActivityResultLauncher<TruvideoSdkCameraConfiguration> cameraScreenLauncher;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
cameraScreenLauncher = registerForActivityResult(
new TruvideoSdkCameraContract(),
result -> {
// Handle result
}
);
openCamera(this);
//...rest of your code
}
}
public void openCamera(Context context) {
if (cameraScreenLauncher == null) return;
TruvideoSdkCameraInformation cameraInfo = TruvideoSdkCamera.getInstance().getInformation();
// you can choose the default camera lens facing
// options: Back, Front
TruvideoSdkCameraLensFacing lensFacing = TruvideoSdkCameraLensFacing.BACK;
// TruvideoSdkCameraLensFacing lensFacing = TruvideoSdkCameraLensFacing.FRONT;
// you can choose if the flash its enabled or not by default
TruvideoSdkCameraFlashMode flashMode = TruvideoSdkCameraFlashMode.OFF;
// TruvideoSdkCameraFlashMode flashMode = TruvideoSdkCameraFlashMode.ON;
TruvideoSdkCameraOrientation orientation = null;
// TruvideoSdkCameraOrientation orientation = TruvideoSdkCameraOrientation.PORTRAIT;
// TruvideoSdkCameraOrientation orientation = TruvideoSdkCameraOrientation.LANDSCAPE_LEFT;
// TruvideoSdkCameraOrientation orientation = TruvideoSdkCameraOrientation.LANDSCAPE_RIGHT;
// TruvideoSdkCameraOrientation orientation = TruvideoSdkCameraOrientation.PORTRAIT_REVERSE;
String outputPath = context.getFilesDir().getPath() + "/camera";
// You can decide the list of allowed resolutions for the front camera
// if you send an empty list, all the resolutions are allowed
List<TruvideoSdkCameraResolution> frontResolutions = new ArrayList<>();
if (cameraInfo.getFrontCamera() != null) {
// if you don't want to decide the list of allowed resolutions, you can send all the resolutions or an empty list
frontResolutions = cameraInfo.getFrontCamera().getResolutions();
//frontResolutions = new ArrayList<>();
// Example of how to allow only the one resolution
// List<TruvideoSdkCameraResolution> resolutions = new ArrayList<>();
// resolutions.add(cameraInfo.getFrontCamera().getResolutions().get(0));
// frontResolutions = resolutions;
}
// You can decide the default resolution for the front camera
TruvideoSdkCameraResolution frontResolution = null;
if (cameraInfo.getFrontCamera() != null) {
// Example of how tho pick the first resolution as the default one
List<TruvideoSdkCameraResolution> resolutions = cameraInfo.getFrontCamera().getResolutions();
if (!resolutions.isEmpty()) {
frontResolution = resolutions.get(0);
}
}
List<TruvideoSdkCameraResolution> backResolutions = new ArrayList<>();
TruvideoSdkCameraResolution backResolution = null;
// You can decide the mode of the camera
// Options: video and picture, video, picture
TruvideoSdkCameraMode mode = TruvideoSdkCameraMode.videoAndPicture();
// TruvideoSdkCameraMode mode = TruvideoSdkCameraMode.VIDEO;
// TruvideoSdkCameraMode mode = TruvideoSdkCameraMode.PICTURE;
TruvideoSdkCameraConfiguration configuration = new TruvideoSdkCameraConfiguration(
lensFacing,
flashMode,
orientation,
outputPath,
frontResolutions,
frontResolution,
backResolutions,
backResolution,
mode
);
cameraScreenLauncher.launch(configuration);
}
Final Result -

Last updated
Was this helpful?