java.lang.IllegalStateException: configure() is valid only at Initialized state; currently during configure()
Maintainers usually reply within 2 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 22/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Domain
- audio-video-rtc, mobile
Research direction
The trace runs from StreamBase.stopStream (StreamBase.kt:252) into prepareEncoders (StreamBase.kt:575) and then VideoEncoder.prepareVideoEncoder (VideoEncoder.java:172), where MediaCodec.configure() is called while a configure is already in progress. Start by reading how stopStream and prepareEncoders manage encoder state, then reproduce with a quick stop during streaming. Done means stopping a stream no longer throws this exception, and the existing stream tests still pass.
Written by the indexing model from the issue text.
Description
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:
- Start screen sharing using
ShareScreenService - 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()
}
}
}
- 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
- Dominant language
- Kotlin
- Stars
- 3k
- Forks
- 946
- Avg merge
- 4d 6h
- Merged PRs (30d)
- 9
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from pedroSG94/RootEncoder
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
pedroSG94/RootEncoder#2213 ·
Maintainers usually reply within 2 days
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
pedroSG94/RootEncoder#2207 · 1 reaction ·
Maintainers usually reply within 2 days
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
pedroSG94/RootEncoder#2203 ·
Maintainers usually reply within 2 days
-
Difficulty 4/5 3-5 days Newbie friendliness 45/100
pedroSG94/RootEncoder#2192 · 2 comments ·
Maintainers usually reply within 2 days
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
pedroSG94/RootEncoder#2177 · 44 comments ·
Maintainers usually reply within 2 days
All issues in pedroSG94/RootEncoder
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
rustyrazorblade/easy-db-lab#1017 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
callstack/react-native-brownfield#492 · 1 comment ·
Maintainers usually reply within 4 days
-
fix: retain the best partial noise-correction solutionPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
world-federation-of-advertisers/cross-media-measurement#4653 ·
Maintainers usually reply within 1 day