{"record":{"id":"d223babd17ae64ec","repo":"dotnet/wpf","slug":"sr-audiovideo-cannotcontrolmedia","errorCode":null,"errorMessage":"SR.AudioVideo_CannotControlMedia","messagePattern":"SR\\.AudioVideo_CannotControlMedia","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/AVElementHelper.cs","lineNumber":271,"sourceCode":"            _speedRatio._wasSet = _speedRatio._isSet = true;\n            _speedRatio._value = speedRatio;\n\n            HandleStateChange();\n        }\n\n        internal\n        void\n        SetState(\n            MediaState      mediaState\n            )\n        {\n            //\n            // If the caller hasn't requested any loaded or unloaded behavior to be manual\n            // then calls to Play/Pause/Stop etc. will never take effect.\n            //\n            if (_loadedBehavior != MediaState.Manual && _unloadedBehavior != MediaState.Manual)\n            {\n                throw new NotSupportedException(SR.AudioVideo_CannotControlMedia);\n            }\n\n            _mediaState._value = mediaState;\n            _mediaState._isSet = true;\n\n            HandleStateChange();\n        }\n\n        internal\n        void\n        SetVolume(\n            double          volume\n            )\n        {\n            _volume._wasSet = _volume._isSet = true;\n            _volume._value = volume;\n\n            HandleStateChange();","sourceCodeStart":253,"sourceCodeEnd":289,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/AVElementHelper.cs#L253-L289","documentation":"AVElementHelper.SetState throws this NotSupportedException when attempting to set the media state (Play/Pause/Stop etc.) while both the loaded and unloaded behaviors are non-Manual (e.g. Play/Close/Pause). With automatic behaviors, direct state control of the MediaElement is not permitted — only Manual behavior allows imperative control.","triggerScenarios":"Calling MediaElement.Play/Pause/Stop (which route through SetState) when LoadedBehavior and UnloadedBehavior are both set to values other than Manual (the default is Play).","commonSituations":"XAML like `<MediaElement LoadedBehavior=\"Play\" ... />` followed by code-behind media.Play(); default behavior is Play, so any imperative call before changing it fails.","solutions":["Set LoadedBehavior=\"Manual\" (and/or UnloadedBehavior=\"Manual\") on the MediaElement before calling Play/Pause/Stop.","If you rely on automatic playback, remove the imperative Play call instead.","Set behaviors in code: media.LoadedBehavior = MediaState.Manual;"],"exampleFix":"<!-- before -->\n<MediaElement x:Name=\"media\" LoadedBehavior=\"Play\" Source=\"a.wmv\"/>\n<!-- after -->\n<MediaElement x:Name=\"media\" LoadedBehavior=\"Manual\" Source=\"a.wmv\"/>\n<!-- then call media.Play() in code -->","handlingStrategy":"validation","validationCode":"if (media.LoadedBehavior != MediaState.Manual && media.UnloadedBehavior != MediaState.Manual)\n    throw new InvalidOperationException(\"Set LoadedBehavior or UnloadedBehavior to Manual before imperative control\");","typeGuard":"bool CanControlManually(MediaElement m) => m.LoadedBehavior == MediaState.Manual || m.UnloadedBehavior == MediaState.Manual;","tryCatchPattern":"try { media.Play(); } catch (NotSupportedException) { media.LoadedBehavior = MediaState.Manual; media.Play(); }","preventionTips":["Set LoadedBehavior=\"Manual\" whenever you call Play/Pause/Stop in code","Remember the default LoadedBehavior is Play, which forbids imperative control"],"tags":["wpf","mediaelement","media-state","not-supported"],"backgroundTag":"unsupported-operation","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}