ilansch
ilansch

Reputation: 4878

WPF playing MediaElement pause does not stop video

programming C# WPF media player application.
I have placed a canvas, on that canvas i placed a mediaelement and button, when clicking the button i want to video to pause, so i made the following function:

private void button1_Click(object sender, RoutedEventArgs e)
{ mediaElement1.Pause(); }

When I debug, it enters the function but does not pause the video.

Why is that ?

Thanks

MediaElement:

<MediaElement Canvas.Left="72" Canvas.Top="33" Height="168" Name="mediaElement1"    Width="271" Source="C:\Users\ilans\Documents\Visual Studio 2010\Projects\SampleWPFVideoApp\SampleWPFVideoApp\SampleWPFVideoApp\Wildlife.wmv" UnloadedBehavior="Manual">
            </MediaElement>

Button:

<Button HorizontalAlignment="Center" VerticalAlignment="Center" Height="45" Width="45" Canvas.Left="70" Canvas.Top="150" Panel.ZIndex="1" Click="button1_Click">
            <Button.Template>
                <ControlTemplate TargetType="Button">
                    <StackPanel>
                        <ContentPresenter Content="{TemplateBinding Content}" />
                    </StackPanel>
                </ControlTemplate>
            </Button.Template>
            <Image Source="Images\play.png"/>
        </Button>

Upvotes: 1

Views: 4836

Answers (1)

Klaus78
Klaus78

Reputation: 11916

Try with LoadedBehavior = Manual

From MediaElement msdn:

LoadedBehavior must be set to Manual in order to interactively control media with the Play, Pause, and Stop methods.

Upvotes: 5

Related Questions