MPEG Demo

/*
  mpeg.c
  
  SDL Example
  Play an MPEG
  
  Bill Kendrick
  1/2000
*/


#include <stdio.h>
#include <stdlib.h>
#include <SDL/SDL.h>
#include <smpeg/smpeg.h>


/* Callback for MPEG library: */

void update(SDL_Surface * screen,
	    Sint32 x, Sint32 y,
	    Uint32 w, Uint32 h)
{
  SDL_UpdateRect(screen,
		 x, y, w, h);
}


/* --- MAIN --- */

int main(int argc, char * argv[])
{
  SDL_Surface * screen;
  SMPEG *mpeg;
  SMPEG_Info info;
  
  
  /* Init SDL: */
  
  SDL_Init(SDL_INIT_VIDEO |
           SDL_INIT_AUDIO);
  
  
  /* Load the MPEG: */
  
  mpeg = SMPEG_new("video.mpg",
		   &info, 1);
  
  
  /* Does it have any video? */
  
  if (info.has_video)
    {
      /* Open display: */
      
      screen =
	SDL_SetVideoMode(info.width,
			 info.height,
			 0, 0);
      
      
      /* Set callback: */
      
      SMPEG_setdisplay(mpeg, screen,
		       NULL, update);
    }
  
  
  /* Play it: */
  
  SMPEG_play(mpeg);
  
  
  /* Wait for it to finish: */
  
  do
    {
      SDL_Delay(250);
    }
  while (!SDL_QuitRequested() &&
	 SMPEG_status(mpeg) ==
         SMPEG_PLAYING);
  
  
  /* Close up and quit: */
  
  SMPEG_delete(mpeg);
  SDL_Quit();
  
  return(0);
}