Movies

From SDL.NET

Introduction

SDL.NET uses the SMPEG library for MPEG-1 movie support. You can play MPEG-1 movies with audio on an SDL.NET Surface.
MoviePlayer Screenshot
Enlarge
MoviePlayer Screenshot

Setup

Take a look at the The absolute newbies guide to SDL.NET for installation instructions. Note that a SMPEG dmg file does not currently exist for OSX.

MoviePlayer Example

The best place to start learning about using SDL.NET's MPEG-1 support is the Movie Player demo. To play a movie you must create a normal SDL.NET Surface.

Surface screen = Video.SetVideoMode(width, height);

One thing to note is the SMPEG library uses its own sound player. It does not use SDL_mixer. If the Mixer object has been initialized, then the movie will play very slowly and without sound. The best way to make sure there is no sound conflict is to turn off the Mixer.

Mixer.Close();

Then you should instantiate the Movie object with the filepath to the movie.

Movie movie = new Movie(filepath + data_directory + "test.mpg");

Tell the Movie object which Surface it will display on.

movie.Display(screen);

And then play it.

movie.Play();

While the movie is playing you should have a tick event so that the app does not exit before the movie ends.

private void Tick(object sender, TickEventArgs e)
{
    if (movie.IsPlaying)
    {
        return;
     }
     else
     {
         movie.Stop();
         movie.Close();
         Events.QuitApplication();
     }
}

When the movie is over make sure to stop it and destroy the object.

movie.Stop();
movie.Close();

There are several Movie fields you can access to get information about the movie file.

Console.WriteLine("Time: " + movie.Length); // Gets length of movie
Console.WriteLine("Width: " + movie.Size.Width); // Gets height of movie
Console.WriteLine("Height: " + movie.Size.Height); // Gets width of movie
Console.WriteLine("HasAudio: " + movie.HasAudio); // Checks to see if movie has audio

The source for the MoviePlayer demo is here (http://cs-sdl.svn.sourceforge.net/viewcvs.cgi/cs-sdl/trunk/SdlDotNet/examples/SdlDotNetExamples/SmallDemos/MoviePlayer.cs?view=markup).