{"record":{"id":"254e9fbba0b2eb9b","repo":"stride3d/stride","slug":"the-media-codec-extractor-has-not-been-initialized","errorCode":null,"errorMessage":"The Media Codec Extractor has not been initialized","messagePattern":"The Media Codec Extractor has not been initialized","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Video/Android/MediaCodecExtractorBase.cs","lineNumber":286,"sourceCode":"            try\n            {\n                ExtractMedia();\n            }\n            catch (Exception)\n            {\n                throw;\n            }\n            finally\n            {\n                Logger.Debug(\"Media Extraction done\");\n                Release();\n            }\n        }\n\n        private void ExtractMedia()\n        {\n            if (MediaDecoder == null)\n                throw new InvalidOperationException(\"The Media Codec Extractor has not been initialized\");\n\n            if (!isInitialized)\n                throw new InvalidOperationException(\"The Media Codec has not been initialized for a media\");\n            \n            var bufferInfo = new MediaCodec.BufferInfo();\n            var waitDefaultTime = TimeSpan.FromMilliseconds(10);\n\n            MediaDecoder.Start();\n            while (true)\n            {\n                var waitTime = waitDefaultTime; // time to wait at the end of the loop iteration\n\n                //Process the commands\n                if (ProcessCommandsAndUpdateCurrentState())\n                    waitTime = TimeSpan.Zero;\n\n                // terminate the thread on disposal\n                if (currentState == SchedulerAsyncCommandEnum.Dispose)","sourceCodeStart":268,"sourceCodeEnd":304,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Video/Android/MediaCodecExtractorBase.cs#L268-L304","documentation":"ExtractMedia is the worker that pulls encoded samples from the MediaExtractor into the decoder. It throws InvalidOperationException when MediaDecoder is null, i.e. the extractor was never given/created its codec, so extraction cannot proceed.","triggerScenarios":"Calling ExtractMedia (directly or via ExtractMediaWorkerFunction) before Initialize created/configured MediaDecoder; Initialize failed earlier (e.g. unreadable file, no track) leaving the decoder null; manual use of the extractor without going through the media player pipeline.","commonSituations":"Starting playback before async initialization completes; swallowing an earlier Initialize exception and then calling Play/extract; reusing an extractor instance after failed setup.","solutions":["Ensure Initialize completed successfully before starting extraction (check isInitialized / await the init task).","Handle Initialize failures (unreadable file, no track) by aborting playback instead of proceeding to extract.","Create/assign a MediaCodec decoder before calling ExtractMedia if driving the extractor manually.","Re-create the extractor instance rather than reusing one whose initialization failed."],"exampleFix":"// before\nextractor.Initialize(url, MediaType.Video);\nextractor.ExtractMediaWorkerFunction(); // may run before init finished\n// after\nif (extractor.Initialize(url, MediaType.Video))\n    extractor.ExtractMediaWorkerFunction();","handlingStrategy":"try-catch","validationCode":"if (extractor.IsInitialized && extractor.MediaDecoder != null)\n    extractor.ExtractMediaWorkerFunction();","typeGuard":"bool ReadyToExtract(MediaCodecExtractorBase e) => e.MediaDecoder != null && e.IsInitialized;","tryCatchPattern":"try { extractor.ExtractMediaWorkerFunction(); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"not been initialized\")) { /* abort playback or re-run Initialize */ }","preventionTips":["Await/verify successful Initialize before starting extraction","Do not swallow Initialize exceptions and continue to playback","Re-create the extractor after any failed initialization rather than reusing it"],"tags":["android","video","media-codec","invalid-state"],"backgroundTag":"invalid-state-transition","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}