Skip to content

java.lang.IllegalStateException: configure() is valid only at Initialized state; currently during configure() #2008

@bhavinatharva

Description

@bhavinatharva

Describe the bug

The application crashes with an IllegalStateException when attempting to stop a screen sharing stream. The error occurs because MediaCodec.configure() is called from an invalid state (during configure()) instead of the required Initialized state.

To Reproduce

Steps to reproduce the behavior:

  1. Start screen sharing using ShareScreenService
  2. Initiate stream stop procedure
if (genericStream.isStreaming) {
                    GlobalScope.launch(Dispatchers.Main) { // Or a custom scope
                        withContext(Dispatchers.IO) { // Perform blocking operation on IO dispatcher
                            genericStream.stopStream()
                        }
                    }
                }
  1. Observe crash with the following stack trace

Expected behavior

The stream should stop cleanly without throwing an IllegalStateException.

Error Log

configure() is valid only at Initialized state; currently during configure()
2025-12-18 14:29:06.518 30621-30665 VideoEncoder            com...rvasystem.quickscreenrecorder  E  Create VideoEncoder failed. (Explain with AI)
                                                                                                    java.lang.IllegalStateException: configure() is valid only at Initialized state; currently during configure()
                                                                                                    
                                                                                                    	at android.media.MediaCodec.native_configure(Native Method)
                                                                                                    	at android.media.MediaCodec.configure(MediaCodec.java:2562)
                                                                                                    	at android.media.MediaCodec.configure(MediaCodec.java:2422)
                                                                                                    	at com.pedro.encoder.video.VideoEncoder.prepareVideoEncoder(VideoEncoder.java:172)
                                                                                                    	at com.pedro.encoder.video.VideoEncoder.prepareVideoEncoder(VideoEncoder.java:237)
                                                                                                    	at com.pedro.library.base.StreamBase.prepareEncoders(StreamBase.kt:575)
                                                                                                    	at com.pedro.library.base.StreamBase.stopStream(StreamBase.kt:252)
                                                                                                    	at com.atharvasystem.quickscreenrecorder.services.ShareScreenService$stopStream$1$1.invokeSuspend(ShareScreenService.kt:148)
                                                                                                    	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:34)
                                                                                                    	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:100)
                                                                                                    	at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.kt:124)
                                                                                                    	at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:89)
                                                                                                    	at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:586)
                                                                                                    	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:820)
                                                                                                    	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:717)
                                                                                                    	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:704)

Environment Information

  • Library Version: com.github.pedroSG94.RootEncoder:library:2.6.6
  • Device: Android Emulator
  • OS: Android 16
  • Media Server: Local RTMP Server
  • Class Used: GenericStream

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions