Question

i have a .mov file that i want to play using MediaElement of WPF , i can play and pause with no worries as i use MediaState.Manual , but i want to show the first image or frame of the video when i load it , the source is set in code behind , i tried MediaElement.ScrubbingEnabled = true both code behind and xaml but it still doesn't show.

Here is my code ( xaml side ) :

   <DockPanel Height="386" HorizontalAlignment="Center"  Name="dockPanel1" VerticalAlignment="Top" Width="731">
        <MediaElement Name="McMediaElement" LoadedBehavior="Manual" UnloadedBehavior="Manual" Stretch="Fill" MediaOpened="Element_MediaOpened" MediaEnded="Element_MediaEnded" OpacityMask="#FF040410" Height="386" IsVisibleChanged="SingAlong_IsVisibleChanged" ScrubbingEnabled="True"></MediaElement>
    </DockPanel>

Code behind ( xaml.cs) :

    private void PlayAudio()
    {


        McMediaElement.LoadedBehavior = MediaState.Manual;
        McMediaElement.Source = new Uri("../../SingAlong/GrassHopper and Ants/ants2.mov", UriKind.RelativeOrAbsolute);
        McMediaElement.ScrubbingEnabled = true;

       McMediaElement.Play();
    }

    private void button1_Click_1(object sender, RoutedEventArgs e) // Play button
    {
        if (McMediaElement.Source != null)
        {
            McMediaElement.Play();
        }
        else
            PlayAudio();
    }

    private void button2_Click(object sender, RoutedEventArgs e) // Pause button
    {
        McMediaElement.Pause();
    }
Was it helpful?

Solution

From what I can gather, you are loading your video (setting the Source) only when you click button1, yet you want the first frame to show before this happens. To accomplish this, you will have to load your video in another method, preferably when your Page or Window loads. Then you can do the following:

McMediaElement.ScrubbingEnabled = true;
McMediaElement.Play();
McMediaElement.Pause();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top