{"record":{"id":"8fc4031ecf43bae3","repo":"stride3d/stride","slug":"videoinstance-avfoundation-failed-to-get-the-audioengine","errorCode":null,"errorMessage":"VideoInstance AVFoundation failed to get the AudioEngine","messagePattern":"VideoInstance AVFoundation failed to get the AudioEngine","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Video/Backends/AVFoundationVideoBackend.cs","lineNumber":348,"sourceCode":"            Instance.NotifyFramePresented();\n        }\n        finally\n        {\n            imported?.Dispose();\n        }\n    }\n\n    private void InitializeAudio(string url, long startPosition, long length)\n    {\n        var audioTracks = asset.TracksWithMediaType(AVMediaTypes.Audio.GetConstant());\n        if (audioTracks == null || audioTracks.Length == 0)\n            return;\n        var videoComponent = Instance.VideoComponent;\n        if (!videoComponent.PlayAudio)\n            return;\n\n        var audioEngine = Instance.Services.GetService<IAudioEngineProvider>()?.AudioEngine\n            ?? throw new Exception(\"VideoInstance AVFoundation failed to get the AudioEngine\");\n\n        audioSynchronizer = new MediaSynchronizer();\n        audioSynchronizer.PlayRange = Instance.PlayRange;\n        audioSynchronizer.IsLooping = Instance.IsLooping;\n        audioSynchronizer.LoopRange = Instance.LoopRange;\n\n        var isSpatialized = videoComponent.AudioEmitters.Any(x => x != null);\n        audioSound = new StreamedBufferSound(audioEngine, audioSynchronizer, url, startPosition, length, isSpatialized);\n        audioSynchronizer.RegisterExtractor(audioSound);\n\n        if (isSpatialized)\n        {\n            if (audioSound.GetCountChannels() == 1)\n            {\n                foreach (var emitter in videoComponent.AudioEmitters)\n                {\n                    if (emitter == null)\n                        continue;","sourceCodeStart":330,"sourceCodeEnd":366,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Video/Backends/AVFoundationVideoBackend.cs#L330-L366","documentation":"While setting up audio for an AVFoundation-backed video instance, the code could not resolve an IAudioEngineProvider (or its AudioEngine) from Instance.Services, so no audio engine exists to register the audio stream with. The library throws rather than silently playing video without audio.","triggerScenarios":"IAudioEngineProvider not registered in the service registry (Services.GetService returned null); audio engine not yet created/initialized when the video initializes; PlayAudio enabled and video has audio but the audio system was never set up.","commonSituations":"Running with a minimal/custom service registry missing Stride's audio module; console/platform builds where audio was intentionally stripped; initializing video before the audio engine in startup order.","solutions":["Register IAudioEngineProvider (and ensure the audio engine is created) in the game's service registry before initializing video","Ensure the Stride audio system is initialized prior to video playback","If audio is unwanted, set VideoComponent.PlayAudio = false so the path is skipped","Check initialization order in Game onStart so audio precedes VideoComponent usage"],"exampleFix":"// before\nvar engine = Instance.Services.GetService<IAudioEngineProvider>()?.AudioEngine\n    ?? throw new Exception(\"...\");\n// after\n// in startup, before video init:\nservices.AddAudio(); // or manually register IAudioEngineProvider\nvar engine = Instance.Services.GetService<IAudioEngineProvider>()?.AudioEngine\n    ?? throw new Exception(\"...\");","handlingStrategy":"type-guard","validationCode":"var provider = Instance.Services.GetService<IAudioEngineProvider>();\nbool audioReady = provider?.AudioEngine != null;\nif (!audioReady) Instance.VideoComponent.PlayAudio = false; // or register audio first","typeGuard":"bool AudioAvailable(SceneInstance s) => s.Services.GetService<IAudioEngineProvider>()?.AudioEngine != null;","tryCatchPattern":"try { backend.Initialize(url, start, len); }\ncatch (Exception ex) when (ex.Message.Contains(\"failed to get the AudioEngine\"))\n{ /* disable PlayAudio or initialize audio system and retry */ }","preventionTips":["Register IAudioEngineProvider during app startup before any video init","Keep Stride audio services intact in custom service registries","Set PlayAudio=false for video-only scenarios"],"tags":["ios","audio","audioengine","dependency"],"backgroundTag":"missing-dependency","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"}