![](https://private-user-images.githubusercontent.com/45873564/299674400-a96f2ccb-1583-40b2-b17f-a5b90ba0b5cd.jpg?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjU1NzkyODksIm5iZiI6MTcyNTU3ODk4OSwicGF0aCI6Ii80NTg3MzU2NC8yOTk2NzQ0MDAtYTk2ZjJjY2ItMTU4My00MGIyLWIxN2YtYTViOTBiYTBiNWNkLmpwZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA5MDUlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwOTA1VDIzMjk0OVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTIzMzE1MDIyNDdiNTYzMjVhODYyZmEzOTYzNjcwZTFmMTQyYTc2OWQwNGJjNmViMjAzOTVhYjdlMTNiMzk1NzUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.BC6UcRR-iUYVkPlPu5YYruvyg7LE0EJ_P03JZK9frfw)
This Module has been designed to simplify the usage of CameraX, making it extremely easy for users to work with. By providing minimal initialization on the user's part, this module facilitates straightforward integration of CameraX functionality into Android applications.
With this interface, users can effortlessly manage various camera-related tasks with minimal setup, ensuring a seamless and hassle-free experience.
If you're using Groovy DSL,
//settings.gradle
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
//app.gradle
dependencies {
implementation 'com.github.lyh990517:Simple_CameraX_Library:latest-release'
}
If you're using Kotlin DSL
//settings.gradle.kts
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
maven(url = "https://jitpack.io")
}
}
//app.gradle.kts
dependencies {
implementation ("com.github.lyh990517:Simple_CameraX_Library:latest-release")
}
-
initialize(context: Context)
: Initializes the CameraX module with the given application context. -
startCamera(lifecycleOwner: LifecycleOwner)
: Starts the camera with the providedLifecycleOwner
to manage the camera's lifecycle. -
takePicture(showMessage: (String) -> Unit)
: Captures a still image and triggers the providedshowMessage
callback with the image result. -
startRecordVideo()
: Starts recording a video. -
stopRecordVideo()
: Stops the video recording. -
resumeRecordVideo()
: Resumes video recording if it was paused. -
pauseRecordVideo()
: Pauses video recording. -
closeRecordVideo()
: Closes the video recording session. -
flipCameraFacing()
: Toggles between the front and back camera facing. -
turnOnOffFlash()
: Toggles the camera flash on or off. -
unBindCamera()
: Unbinds and releases the camera resources. -
getPreviewView(): PreviewView
: Returns thePreviewView
associated with the camera for displaying the camera preview. -
getFlashState(): StateFlow<Boolean>
: Provides aStateFlow
that emits the current state of the camera flash (on or off). -
getFacingState(): StateFlow<Int>
: Provides aStateFlow
that emits the current camera facing (front or back). -
getRecordingState(): StateFlow<RecordingState>
: Provides aStateFlow
that emits the current video recording state (recording, paused, or stopped). -
getRecordingInfo(): SharedFlow<RecordingInfo>
: Provides aSharedFlow
that emits information about the video recording, such as duration, file path, and other relevant details.
This CameraX Interface simplifies camera integration in your Android app, making it easier to manage and control camera functionality.
Here's an example of how to use CameraX
@Composable
fun Example() {
val context = LocalContext.current
val lifecycleOwner = LocalLifecycleOwner.current
val cameraScope = rememberCoroutineScope()
val cameraX = remember { CameraXFactory.create() }
val previewView = remember { mutableStateOf<PreviewView?>(null) }
val facing = cameraX.getFacingState().collectAsState()
LaunchedEffect(Unit) {
cameraX.initialize(context = context)
previewView.value = cameraX.getPreviewView()
}
DisposableEffect(facing.value) {
cameraScope.launch(Dispatchers.Main) {
cameraX.startCamera(lifecycleOwner = lifecycleOwner)
}
onDispose {
cameraX.unBindCamera()
}
}
Button(
onClick = { cameraX.takePicture {} }
) {
Text("takePicture")
}
}
Feel free to customize CameraX Interface to suit your specific needs. Whether it's adjusting camera settings, tweaking the user interface, or tailoring the behavior, you have the flexibility to make it your own.
If you find CameraX Interface helpful and it makes your development journey smoother, we kindly ask for your support. Please consider ⭐starring⭐ this repository—it motivates us to keep improving and providing you with valuable tools.