How to use Video in XNA

In this mini-article I will show you how to use Video in XNA.

We have a project Structure like this:

1.gif
 

We will be using Wildlife.wmv for demonstration in our sample(which can be found in your Videos folder inside My Documents)

We are adding these variables first:

Video myVideoFile;
VideoPlayer videoPlayer = new VideoPlayer();

After that add these to LoadContent:

myVideoFile = Content.Load<Video>("Videos\\Wildlife");

Inside Update call:

videoPlayer.Play(myVideoFile);

And in Draw Function:

spriteBatch.Begin();
spriteBatch.Draw(videoPlayer.GetTexture(), new Rectangle(0, 0, myVideoFile.Width, myVideoFile.Height),Color.CornflowerBlue);
spriteBatch.End(); 

When you run the project you will see a video running inside XNA Window.

Windows-Game.jpg

Well Done. You have successfully displayed Video in XNA.

Up Next
    Ebook Download
    View all
    Learn
    View all
    Araf Global is a software consultancy company founded in 2016 focusing on cutting edge technologies.