RedApparat / Fotoapparat

Making Camera for Android more friendly. 📸
Apache License 2.0
3.82k stars 407 forks source link

FotoApparat not working on Android Emu #287

Closed Pravez closed 5 years ago

Pravez commented 6 years ago

What are you trying to achieve or the steps to reproduce?

First of all, thank you for your amazing work ! I am trying your library to analyze preview frames with OpenCV. Problem is the io.fotoapparat.view.CameraView is only showing a blank screen on Android Emulator. I tested on a real device and it worked without any problems, but for networking reasons I need it to run on an emulated device. Maybe I did something wrong during the initialization phase ? I tried my android app on a pixel and nexus devices, with APIs 27 and 28, and none of them were working ...

I am using FA 2.3.2.

How did you initialize FA?

    private CameraView cameraView;
    private Fotoapparat fotoapparat;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.foto_camera_preview);
        cameraView = findViewById(R.id.foto_camera_view);
        textView = findViewById(R.id.textView);

        hasCameraPermission = ContextCompat.checkSelfPermission(getBaseContext(), Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED;

        fotoapparat = createFotoApparat();
    }

    private Fotoapparat createFotoApparat() {
        return Fotoapparat
                .with(this)
                .into(cameraView)
                .previewScaleType(ScaleType.CenterCrop)
                .photoResolution(ResolutionSelectorsKt.highestResolution())
                .lensPosition(LensPositionSelectorsKt.back())
                .focusMode(SelectorsKt.firstAvailable(
                        FocusModeSelectorsKt.continuousFocusPicture(),
                        FocusModeSelectorsKt.autoFocus(),
                        FocusModeSelectorsKt.fixed()
                ))
                .flash(SelectorsKt.firstAvailable(
                        FlashSelectorsKt.autoRedEye(),
                        FlashSelectorsKt.autoFlash(),
                        FlashSelectorsKt.torch()
                ))
                .frameProcessor(processor)
                .build();
    }

    @Override
    protected void onStop() {
        super.onStop();
        if(hasCameraPermission)
            fotoapparat.stop();
        processor.stopTimer();
    }

    @Override
    protected void onStart() {
        super.onStart();
        if(hasCameraPermission)
            fotoapparat.start();
        processor.startTimer();
    }
kleinsenberg commented 5 years ago

This generally happens because the emulator does not support one of the hardware requirements in your configuration. What I suspect here is that none of your flash selectors here can be resolved, so I would recommend adding FlashSelectorsKt.off() as your last option.

Diolor commented 5 years ago

I will close this one, unless there is further input. :) Thanks @kleinsenberg !