Video
From XNAWiki
General Information
Since XNA Game Studio 3.1 the following video support is available:
- Take video processed through XNA Game Studio and play it back full screen.
- Take video processed through XNA Game Studio and apply it as an animated texture.
To enable video support for an existing project, it needs to be upgraded to Xna v3.1 (right click on project in the solution explorer and choose Upgrade Solution).
Video Files
To import video files as XNA Content, the following requirements must be met:
- Format: Windows Media Video, Series 9 using the “Main” profile.
- Maximum resolution: 1280x720
- Encoding: constant bit rate (CBR)
- Protection: must be non-DRM
- Audio: one track WMA in constant bit rate (CBR)
Encode360 can be used to create the required video file.
Code Sample
// Create the variables needed to hold and play back video.
Video myVideoFile;
VideoPlayer videoPlayer;
// Create the VideoPlayer
videoPlayer = new VideoPlayer();
// In LoadContent():
// Load a video file
myVideoFile = Content.Load<Video>(@"Sample");
// In Update():
// Start the video playback
videoPlayer.Play(myVideoFile);
// Stop the video playback
videoPlayer.Stop();
// In Draw():
// Render the video in it's orginal resolution to the screen using SpriteBatch
spriteBatch.Begin();
if (videoPlayer.State == MediaState.Playing)
{
spriteBatch.Draw(videoPlayer.GetTexture(), new Rectangle(0, 0, myVideoFile.Width, myVideoFile.Height), Color.White);
}
spriteBatch.End();