{"record":{"id":"dd150ae8bf5e20d6","repo":"stride3d/stride","slug":"unable-to-read-0-streamedbuffersoundsource-mediacodec","errorCode":null,"errorMessage":"Unable to read: {0} ","messagePattern":"Unable to read: (.+?) ","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Audio/StreamedBufferSoundSource.MediaCodec.cs","lineNumber":33,"sourceCode":"        private MediaCodec audioMediaDecoder = null;\n        private int trackIndexAudio = -1;\n\n        private Java.IO.File InputFile;\n        private Java.IO.FileInputStream InputFileStream;\n\n        private bool extractionOutputDone = false;\n        private bool extractionInputDone = false;\n\n        partial void InitializeMediaExtractor(string mediaDataUrl, long startPosition, long length)\n        {\n            if (mediaDataUrl == null)\n                throw new ArgumentNullException(nameof(mediaDataUrl));\n\n            ReleaseMediaInternal();\n\n            InputFile = new Java.IO.File(mediaDataUrl);\n            if (!InputFile.CanRead())\n                throw new Exception(string.Format(\"Unable to read: {0} \", InputFile.AbsolutePath));\n\n            InputFileStream = new Java.IO.FileInputStream(InputFile.AbsolutePath);\n\n            audioMediaExtractor = new MediaExtractor();\n            audioMediaExtractor.SetDataSource(InputFileStream.FD, startPosition, length);\n            trackIndexAudio = FindAudioTrack(audioMediaExtractor);\n            if (trackIndexAudio < 0)\n            {\n                ReleaseMediaInternal();\n                Logger.Error($\"The input file '{mediaDataUrl}' does not contain any audio track.\");\n                return;\n            }\n\n            audioMediaExtractor.SelectTrack(trackIndexAudio);\n            var audioFormat = audioMediaExtractor.GetTrackFormat(trackIndexAudio);\n\n            var mime = audioFormat.GetString(MediaFormat.KeyMime);\n            audioMediaDecoder = MediaCodec.CreateDecoderByType(mime);","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Audio/StreamedBufferSoundSource.MediaCodec.cs#L15-L51","documentation":"MediaCodec (Android) backend of StreamedBufferSoundSource throws this in InitializeMediaExtractor when the given mediaDataUrl points to a Java.IO.File that reports CanRead() == false. The library refuses to open a media source it cannot read at the filesystem level. It guards the MediaExtractor.SetDataSource call with an early, descriptive check.","triggerScenarios":"Passing a path to InitializeMediaExtractor that does not exist, lacks read permission, is a directory, or lies in app-private storage inaccessible to the current context (e.g. raw absolute path to shared storage on modern Android without permissions).","commonSituations":"Hard-coded absolute paths like /storage/emulated/0/... on Android 10+ scoped storage; missing READ_EXTERNAL_STORAGE permission; typo in the media file path; asset bundled in the APK referenced as a file path instead of streamed via AssetFileDescriptor.","solutions":["Verify the file exists and is readable: new Java.IO.File(path).Exists() && CanRead() before calling","Request runtime READ_EXTERNAL_STORAGE / MANAGE_EXTERNAL_STORAGE permissions on Android, or use app-internal storage for media files","For bundled assets, copy the asset to app cache/files first, or use a data source that supports content:// streams","Check the path for typos and confirm InputFile.AbsolutePath points to the actual media file, not a directory"],"exampleFix":"// before\nvar source = new StreamedBufferSoundSource(\"/storage/emulated/0/Music/track.ogg\", services);\n// after\nvar file = new Java.IO.File(path);\nif (!file.Exists() || !file.CanRead())\n    throw new FileNotFoundException($\"Media file not readable: {path}\");\nvar source = new StreamedBufferSoundSource(path, services);","handlingStrategy":"validation","validationCode":"var f = new Java.IO.File(path);\nif (f == null || !f.Exists() || f.IsDirectory || !f.CanRead())\n    throw new FileNotFoundException($\"Media file not readable: {path}\");","typeGuard":null,"tryCatchPattern":"try\n{\n    source = new StreamedBufferSoundSource(path, services);\n}\ncatch (Exception ex) when (ex.Message.StartsWith(\"Unable to read:\"))\n{\n    Logger.Error($\"Cannot read media at {path}: {ex.Message}\");\n    source = null;\n}","preventionTips":["Always check File.Exists() and CanRead() before creating streamed sources","Request storage permissions at runtime on Android 6+","Copy APK-bundled assets to internal storage before opening them as files","Avoid hard-coded absolute paths to shared storage; prefer app-internal paths"],"tags":["android","audio","mediacodec","filesystem"],"backgroundTag":"file-read-failed","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"}