5

I'm following this original CameraX Example for Android here: https://developer.android.com/codelabs/camerax-getting-started#5 and here: https://github.com/android/camera-samples/blob/main/CameraXBasic/app/src/main/java/com/android/example/cameraxbasic/fragments/CameraFragment.kt#L337

I want to instantiate my Preview like in the example:

       val preview = Preview.Builder()
           .build()
           .also {
               it.setSurfaceProvider(viewFinder.surfaceProvider)
           }

But then i realize ... Well , what a pleasant surprise - viewFinder / androidx.camera.view.PreviewView is from a library which is only an alpha version

    implementation 'androidx.camera:camera-view:1.0.0-alpha24'

(see here) https://github.com/android/camera-samples/blob/main/CameraXBasic/app/build.gradle

I of course don't want to use an alpha version! So i thought okay maybe i Can implement my own SurfaceProvider

documentation suggests i could do something like that:

         * class MyGlSurfaceProvider implements Preview.SurfaceProvider {
         *     // This executor must have also been used with Preview.setSurfaceProvider() to
         *     // ensure onSurfaceRequested() is called on our GL thread.
         *     Executor mGlExecutor;
         *
         *     {@literal @}Override
         *     public void onSurfaceRequested(@NonNull SurfaceRequest request) {
         *         // If our GL thread/context is shutting down. Signal we will not fulfill
         *         // the request.
         *         if (isShuttingDown()) {
         *             request.willNotProvideSurface();
         *             return;
         *         }
         *
         *         // Create the surface and attempt to provide it to the camera.
         *         Surface surface = resetGlInputSurface(request.getResolution());
         *
         *         // Provide the surface and wait for the result to clean up the surface.
         *         request.provideSurface(surface, mGlExecutor, (result) -> {
         *             // In all cases (even errors), we can clean up the state. As an
         *             // optimization, we could also optionally check for REQUEST_CANCELLED
         *             // since we may be able to reuse the surface on subsequent surface requests.
         *             closeGlInputSurface(surface);
         *         });
         *     }
         * }

yeah but this example seems somewhat incomplete. And i don't know how to implement that properly... So any suggestions how i can implement my own SurfaceProvider?

MinionDeveloper
  • 203
  • 1
  • 2
  • 9
  • 1
    received this kind reply from camera x discussion group: https://groups.google.com/a/android.com/g/camerax-developers/c/Q8kGNP6hwJ8 – MinionDeveloper Jun 22 '21 at 07:17

0 Answers0