This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if(event == VideoRecordEvent.Finalize) { | |
| if (!event.hasError()) { | |
| val playback = Intent(Intent.ACTION_VIEW).apply { | |
| setDataAndType(event.outputResults.outputUri, "video/*") | |
| } | |
| startActivity(playback); | |
| } else { | |
| // update app state when the capture failed. | |
| recording?.close() | |
| recording = null |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| val contentValues = ContentValues().apply { | |
| put(MediaStore.MediaColumns.DISPLAY_NAME, “CameraX-VideoCapture”) | |
| put(MediaStore.MediaColumns.MIME_TYPE, "video/mp4") | |
| } | |
| val mediaStoreOutputOptions = MediaStoreOutputOptions | |
| .Builder(contentResolver, MediaStore.Video.Media.EXTERNAL_CONTENT_URI) | |
| .setContentValues(contentValues) | |
| .build() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| val recordingListener = Consumer<VideoRecordEvent> { event -> | |
| when(event) { | |
| is VideoRecordEvent.Start -> { | |
| val msg = “Capture Started” | |
| Toast.makeText(getActivity(), msg, Toast.LENGTH_SHORT) | |
| .show() | |
| // update app internal recording state | |
| … | |
| } | |
| is VideoRecordEvent.Finalize -> { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @androidx.annotation.OptIn(ExperimentalCamera2Interop::class) | |
| val cameraSelector = CameraSelector.Builder() | |
| .addCameraFilter { | |
| it.filter { camInfo -> | |
| val level = Camera2CameraInfo.from(camInfo) | |
| .getCameraCharacteristic( | |
| CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL | |
| ) | |
| level == CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_3 | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| try { | |
| camera = cameraProvider.bindToLifecycle( | |
| viewLifecycleOwner, | |
| CameraSelector.DEFAULT_BACK_CAMERA, | |
| videoCapture, | |
| preview | |
| ) | |
| } catch (exc: Exception) { | |
| // we are on the main thread, let's reset the controls on the UI. | |
| Log.e(TAG, "Use case binding failed", exc) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| val recorder = Recorder.Builder() | |
| .setQualitySelector(qualitySelector) | |
| .build() | |
| // Create the VideoCapture UseCase and make it available to use | |
| // in the other part of the application. | |
| videoCapture = VideoCapture.withOutput(recorder) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fun getResolutions(selector:CameraSelector, | |
| provider:ProcessCameraProvider | |
| ): Map<Quality, Size> { | |
| return selector.filter(provider.availableCameraInfos).firstOrNull() | |
| ?.let { camInfo -> | |
| QualitySelector.getSupportedQualities(camInfo) | |
| .associateWith { quality -> | |
| QualitySelector.getResolution(camInfo, quality)!! | |
| } | |
| } ?: emptyMap() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| val selector = QualitySelector | |
| .from( | |
| Quality.UHD, | |
| FallbackStrategy.higherQualityOrLowerThan(Quality.SD) | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| dependencies { | |
| def camerax_version = "1.1.0-beta01" | |
| implementation "androidx.camera:camera-core:${camerax_version}" | |
| implementation "androidx.camera:camera-camera2:${camerax_version}" | |
| implementation "androidx.camera:camera-lifecycle:${camerax_version}" | |
| implementation "androidx.camera:camera-video:${camerax_version}" | |
| implementation "androidx.camera:camera-view:${camerax_version}" | |
| implementation "androidx.camera:camera-extensions:${camerax_version}" | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| D/AndroidRuntime( 7236): | |
| D/AndroidRuntime( 7236): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<< | |
| D/AndroidRuntime( 7236): CheckJNI is OFF | |
| E/art ( 7236): Unrecognized option -XX:mainThreadStackSize=24K | |
| W/art ( 7236): Ignoring unknown -Xgc option: precise | |
| W/art ( 7236): Failed to find ELF magic in /system/framework/am.odex: dey | |
| E/memtrack( 7236): Couldn't load memtrack module (No such file or directory) | |
| E/android.os.Debug( 7236): failed to load memtrack module: -2 | |
| W/art ( 7236): JNI RegisterNativeMethods: attempt to register 0 native methods for android.content.res.Configuration | |
| D/AndroidRuntime( 7236): Calling main entry com.android.commands.am.Am |
NewerOlder