Search code examples
c#wpfmp4mediaelementmanual

WPF MediaElement doens't show video when LoadedBehavior="Manual"


When LoadedBehavior attribute of MediaElement, is set to "Manual", I can see the video in the previewer, but when I run the application, the video is not displayed at all.

When LoadedBehavior is set to "Play", it works fine.

The 'Build Action' property of the video file is set to "Content". The 'Copy to output' property of the video file is set to "Copy Always".

This is the code which doesn't display the Video:

   <MediaElement Source="Videos\abc.mp4" Height="300" Width="300" LoadedBehavior="Manual"/>

Solution

  • So I expect the media player to be displayed with the right buttons, and let the user to chose when to play, pause, stop

    Then your expectations are simply plain wrong because the MediaElement control doesn't come with any such buttons.

    You'll need to add the buttons yourself and then hook up event handlers or commands to them where you call the Play, Pause and Stop methods.

    The other option is to call the method(s) programmatically without the use of any buttons in the UI, but when you set the LoadedBehavior to Manual, you have to call Play() explicitly one way or the other for the media to play.