{"record":{"id":"8e8d39ee45fb0f17","repo":"SubtitleEdit/subtitleedit","slug":"failed-to-initialize-mpv-mpvcontext-geterrorstr","errorCode":null,"errorMessage":"Failed to initialize mpv: {_mpvContext.GetErrorString(err)}","messagePattern":"Failed to initialize mpv: (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/ui/Features/Video/TextToSpeech/ActorVoices/ActorVoiceMappingViewModel.cs","lineNumber":418,"sourceCode":"        {\n            row.IsPlaying = false;\n            generatingAudioVm.Close();\n        }\n    }\n\n    private async Task PlayAudio(string fileName)\n    {\n        lock (_playLock)\n        {\n            _mpvContext?.Stop();\n            _mpvContext?.Dispose();\n\n            _mpvContext = new LibMpvDynamicPlayer();\n            _mpvContext.LoadLib();\n            var err = _mpvContext.Initialize();\n            if (err < 0)\n            {\n                throw new InvalidOperationException($\"Failed to initialize mpv: {_mpvContext.GetErrorString(err)}\");\n            }\n        }\n\n        await _mpvContext.LoadAudio(fileName);\n    }\n\n    [RelayCommand]\n    private void ApplyDefaultToAll()\n    {\n        if (_fallbackEngine == null)\n        {\n            return;\n        }\n\n        foreach (var row in Rows)\n        {\n            if (row.SelectedEngine == _fallbackEngine)\n            {","sourceCodeStart":400,"sourceCodeEnd":436,"githubUrl":"https://github.com/SubtitleEdit/subtitleedit/blob/17a9f0748781032255db3526b7215d2fb891e3af/src/ui/Features/Video/TextToSpeech/ActorVoices/ActorVoiceMappingViewModel.cs#L400-L436","documentation":"LibMpvDynamicPlayer.Initialize() returned a negative mpv error code; GetErrorString maps it to a human-readable string. This means the libmpv shared library could not be brought up — missing dependency, ABI mismatch, or init failure inside mpv itself. Thrown inside PlayAudio under _playLock after a fresh LibMpvDynamicPlayer is created each call.","triggerScenarios":"LoadLib() succeeded but Initialize() < 0: libmpv dll/so missing from the app directory; wrong architecture (x86 vs x64) vs the process; corrupt libmpv; required codec/sentenceit libs absent; AV/sandbox blocking the dll.","commonSituations":"App moved without its libmpv binary; user replaced libmpv with an incompatible version; fresh machine missing VC++ runtime; antivirus quarantined the dll.","solutions":["Re-ship/restore the libmpv binary in the application directory.","Match libmpv architecture to the process bitness (x64 process needs x64 libmpv).","Read _mpvContext.GetErrorString(err) in the message for the specific mpv error code.","Reinstall the VC++ runtime and exclude the app folder from AV."],"exampleFix":"// before: assume init always works\nvar err = _mpvContext.Initialize();\n// after: keep the error string in the surface message (already done) and\n//       guard LoadLib separately\nif (!_mpvContext.LoadLib())\n    throw new InvalidOperationException(\"libmpv not found next to the executable\");","handlingStrategy":"try-catch","validationCode":"if (!_mpvContext.LoadLib()) return Invalid(\"libmpv not found next to the executable\");","typeGuard":null,"tryCatchPattern":"try { await PlayAudio(fileName); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"Failed to initialize mpv\"))\n{ /* surface GetErrorString; offer to re-install libmpv */ }","preventionTips":["Ship the matching-architecture libmpv with the app.","Call LoadLib() and check its bool before Initialize().","Log GetErrorString(err) so the mpv error code is never lost."],"tags":["mpv","audio-playback","native-library","text-to-speech"],"backgroundTag":null,"analyzedSha":"17a9f0748781032255db3526b7215d2fb891e3af","analyzedAt":"2026-08-13T18:11:43.374Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}