Hi!
I have a special type of suggestion/request regarding managing lifecycle with multiple UseCases. Now it's happening that when one of UseCases is stopped, whole CameraX stop. It would be nice if API could be more flexible regarding that.
Let me go into more details why I need this.
We have an app which is streaming camera and user also see preview of what is streamed. CameraX is created in foreground service with two Preview UseCases, one for PreviewView and another for encoder and streamer. First Preview is shared with UI over LiveData and when fragment is visible it shows preview. Everything fine here until we minimize fragment (collapse/minimize it like in audio player, so you can browse around an app while still streaming), which is done with MotionLayout. In that minimized view we don't have a PreviewView so it's lifecycle is stopped which also unbinds all UseCases. Here comes a problem for us. Because all UseCases are stopped, also encoder and streamer is stopped. And whole concept of minimized view is broken. Hope it's clear enough where our problem is :)
So, we tackle that with a custom surface provider based on
SurfaceTextureProvider. That solves a problem with lifecycle, but problem arrives with correctly transforming preview. We tried with using
PreviewTransformation, but we couldn't make it work correctly, guess some required plumbing was missing. So we went with some older implementations of
preview transformation, but it's not always perfect. Stil looking into that how to make it reliable, because sometimes transformstions are correct, sometimes are stretched.
If there is some other solution to that, please let me know, would be glad if you could help me.
TLDR;
Would it be possible to create a PreviewView with an option to not being bound to lifecycle and so not unbind UseCase when removed? Does this make sense or is there any other solution for that?