Giter Club home page Giter Club logo

Comments (4)

ujizin avatar ujizin commented on May 25, 2024

Oh, got it! I don't see any issue with making this change.

I'll create a new release as soon as possible with this update. If you'd like, please feel free to open the pull request

And thanks for opening the issue!

from camposer.

Myzel394 avatar Myzel394 commented on May 25, 2024

Perfect, thanks for your response @ujizin! I'm shamelessly going to use this thread to ask you a question that's not related to this issue. Do you know if you can use cameraX in a foreground service? :D I couldn't find anything about it on the internet and my attempts all failed. Since you seem to know a lot about cameraX, I was wondering if you know whether that is even possible :D

from camposer.

ujizin avatar ujizin commented on May 25, 2024

To be honest, I've never seen it, but this discussion might be useful for you: https://groups.google.com/a/android.com/g/camerax-developers/c/CqPqokS4Lkk

I'll try to create a sample later. If I succeed, I'll send it to you.

ps: and don't worry about using this thread to ask questions โ€“ it's related to the topic of this thread too ๐Ÿ˜„

from camposer.

Myzel394 avatar Myzel394 commented on May 25, 2024

That was quick, thank you very much!

Regarding CameraX in Foreground Services, it seems as if that is really not possible as camerax needs to run on the main thread, I tried running this service:

@ExperimentalVideo class VideoRecorderService: LifecycleService() {
    lateinit var cameraController: LifecycleCameraController

    private var job = SupervisorJob()
    private var scope = CoroutineScope(Dispatchers.IO + job)

    override fun onCreate() {
        super.onCreate()

        scope.launch {
            cameraController = LifecycleCameraController(this@VideoRecorderService)

            // Hack to make sure camera is initialized
            delay(2000L)
            startRecording()
        }
    }

    fun startRecording() {
        cameraController.startRecording(
            OutputFileOptions.builder(
                File(externalCacheDir!!.absolutePath + "/video.mp4"),
            ).build(),
            ContextCompat.getMainExecutor(this),
            object: OnVideoSavedCallback {
                override fun onVideoSaved(outputFileResults: OutputFileResults) {
                    println("Video saved")
                }

                override fun onError(videoCaptureError: Int, message: String, cause: Throwable?) {
                    println("Video error")
                }
            }
        )

    }
}

but this results in the following error:

java.lang.IllegalStateException: Not in application's main thread

I guess I'll stick to Camera2 :/

from camposer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.