Original Source, Royce Tucker – Lead Programmer of 40 Past Midnight
Rendering video for opening or transition scenes
The video rendering I'm about to describe is it's own scene that will be played for the duration of the video before loading the next scene. It would work great for opening cinematics or video transitions between two levels.
First of all, you have to make sure to you a certain DirectX dll linked to your project. Right click your project in Visual Studio and click on “Add Reference.” Under the “.NET” tab, scroll down to Microsoft.DirectX.AudioVideoPlayback and add it to the project. Then just access it like so:
using Microsoft.DirectX.AudioVideoPlayback;
Now, make a custom scene and add a Video object to handle playback, like so:
using Visual3D;
using Microsoft.DirectX.AudioVideoPlayback;
public class VideoTransitionScene : Scene
{
private Video video;
public VideoTransitionScene()
: base("AwesomeCinimaticOpeningScene")
{
}
Now we'll initialize the video and begin playback:
protected override void OnStarted()
{
base.OnStarted();
video = new Video(filepath, false);
video.Owner = World.RenderPipeline.OutputRenderWindow;
video.Play();
}
For the file path, you may have to use an exact path from the working directory. For example, I had to use "Manhattan Project/Assets/Opening.avi" to get my video file to play properly. Also, I have not tested other file types. I know .avi format works, but I'm unsure of others.
Next, we need to add a check to switch to the next scene as soon as the video is done playing. This is done like so:
public override void Update()
{
base.Update();
if( video.CurrentPosition >= video.Duration )
World.WorldApp.ShowScene( nextScene );
}
NextScene is simply a string that matches the name of the class you want to switch too. For example, to switch to MainMenu, you would use “MainMenu”
Then all we have left to do is properly dispose of the video.
protected override void OnDispose(bool isDisposing)
{
base.OnDispose(isDisposing);
video.Dispose();
video = null; // Just in case, to make sure everything is taken out of memory
}
}
And thats it! I hope this will help a few of you out there.