Mountain Man
Mountain Man

Reputation: 119

How do you make a video play automatically on a wpf program startup using a MediaElement

I'm sorry if this comes off as a rookie question, but I have spent more time on this than I care to admit.

I'm trying to have a video autoplay on the program's startup. The main window preview shows that the video has been found; however, when I start the program I get a white screen. If someone could help me that would be much appreciated. Thank you and have a wonderful day!

Below is the entirety of the program's xaml code. I have tried running it in other builds of visual studios with no success - so I don't think it's vs.

<Window x:Class="SUP.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:SUP"
        mc:Ignorable="d"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <MediaElement Name="VidPlayer" HorizontalAlignment="Left" Height="321" VerticalAlignment="Top" Width="518" Source="Videos\Vid.mp4" LoadedBehavior="Play"></MediaElement>
    </Grid>

</Window>

Upvotes: 0

Views: 2478

Answers (1)

Roger Leblanc
Roger Leblanc

Reputation: 1583

Make sure your video file has Copy To Ouput Directory set to Copy always or Copy if newer.

Copy to output directory

Upvotes: 5

Related Questions