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
publicclassYourActivityextendsAppCompatActivity{ActivityResultLauncher<TruvideoSdkCameraConfiguration> cameraScreenLauncher; @OverrideprotectedvoidonCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); cameraScreenLauncher =registerForActivityResult(new TruvideoSdkCameraContract(), result -> {// Handle result } );//...rest of your code }}
classYourActivity: AppCompatActivity() {var cameraScreenLauncher : ActivityResultLauncher<TruvideoSdkCameraConfiguration>?=nulloverridefunonCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState) cameraScreenLauncher =registerForActivityResult(TruvideoSdkCameraContract()) { result: List<TruvideoSdkCameraMedia> ->// Handle result }//...rest of your code }}
Step 2 : Get the Camera Information
This function will provide the default configuration of the camera
Step 3 : Create new configuration to give to the camera
Step 4 : Present the camera with the configuration using TruvideoSdkCameraConfiguration
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);
}
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
class YourActivity: AppCompatActivity() {
var cameraScreenLauncher : ActivityResultLauncher<TruvideoSdkCameraConfiguration>?=null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
cameraScreenLauncher = registerForActivityResult(TruvideoSdkCameraContract()) { result: List<TruvideoSdkCameraMedia> ->
// Handle result
}
openCamera(this)
//...rest of your code
}
}
fun openCamera() {
// Start camera with configuration
// if camera is not available, it will return null
if (cameraScreenLauncher == null) return;
// Get camera information
val cameraInfo = TruvideoSdkCamera.getInformation()
// you can choose the default camera lens facing
// options: Back, Front
val lensFacing = TruvideoSdkCameraLensFacing.BACK
// TruvideoSdkCameraLensFacing lensFacing = TruvideoSdkCameraLensFacing.FRONT;
// You can choose if the flash is on or off by default
val flashMode = TruvideoSdkCameraFlashMode.OFF
// val flashMode = TruvideoSdkCameraFlashMode.ON
// You can choose the camera orientation
// Options: null, Portrait, LandscapeLeft, LandscapeRight, PortraitReverse
// Null means any orientation
val orientation: TruvideoSdkCameraOrientation? = null
// TruvideoSdkCameraOrientation orientation = TruvideoSdkCameraOrientation.PORTRAIT;
// TruvideoSdkCameraOrientation orientation = TruvideoSdkCameraOrientation.LANDSCAPE_LEFT;
// TruvideoSdkCameraOrientation orientation = TruvideoSdkCameraOrientation.LANDSCAPE_RIGHT;
// TruvideoSdkCameraOrientation orientation = TruvideoSdkCameraOrientation.PORTRAIT_REVERSE;
// You can choose where the files will be saved
val outputPath = context.filesDir.path + "/camera"
// You can decide the list of allowed resolutions for the front camera
// if you send an empty list, all the resolutions are allowed
var frontResolutions: List<TruvideoSdkCameraResolution> = ArrayList()
if (cameraInfo.frontCamera != 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.frontCamera!!.resolutions
//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
var frontResolution: TruvideoSdkCameraResolution? = null
if (cameraInfo.frontCamera != null) {
// Example of how tho pick the first resolution as the default one
val resolutions = cameraInfo.frontCamera!!.resolutions
if (resolutions.isNotEmpty()) {
frontResolution = resolutions[0]
}
}
val backResolutions: List<TruvideoSdkCameraResolution> = ArrayList()
val backResolution: TruvideoSdkCameraResolution? = null
// You can decide the mode of the camera
// Options: video and picture, video, picture
val mode = TruvideoSdkCameraMode.videoAndPicture()
// TruvideoSdkCameraMode mode = TruvideoSdkCameraMode.VIDEO;
// TruvideoSdkCameraMode mode = TruvideoSdkCameraMode.PICTURE;
val configuration = TruvideoSdkCameraConfiguration(
lensFacing = lensFacing,
flashMode = flashMode,
orientation = orientation,
outputPath = outputPath,
frontResolutions = frontResolutions,
frontResolution = frontResolution,
backResolutions = backResolutions,
backResolution = backResolution,
mode = mode
)
cameraScreenLauncher.launch(configuration)
}