CRM32Pro SDK  v5.22
Example05_VideoPlayer.cpp


/*--------------------------------------------
Examples - CRM32Pro SDK - Roberto Prieto
Copyright (C) 2001-2011 MegaStorm Systems
--------------------------------------------
Example 5: video player
-----------------------
- Initialize SDL and CRM32Pro.
- Printing help on console.
- Use of log system.
- Initialize graphics: window icon, video mode and cursor.
- Play a MPEG-I(video & audio stream) until the end or ESC/s key are pressed.
- Show FX effects on video playback (using cursor keys: <- and ->)
- Exiting using the right way ;)
This example is totally free and can be used without
any restriction but there is not any warranty for its usage.
Please, do not forget to include a copy of all the library licenses
located at /licenses directory if you distribute or share it.
Roberto Prieto
contact@megastormsystems.com
http://www.megastormsystems.com
*/
// ---Includes---
#include "CRM32Pro.h"
// ---Defines---
#define EXAMPLE_VERSION "Example 5: Video player"
#define GFX_RESOURCE "data/gfx.dpf" // DPF with graphic resources
// ---Prototypes---
int ChangeFX(int kPressed,SDL_Surface *sFrame,SDL_Rect *rDst);
void PrintHelp(char *sErrMsg = NULL);
// -------------MAIN FUNCTION----------------
int main(int argc,char *argv[])
{
Uint8 done = 0;
// -Log system initialize-
ILogSystem.Init("VideoPlayer.log",LOG_CONSOLE | LOG_FILE,LOG_NORMAL,EXAMPLE_VERSION);
// -Print help without any arguments-
if(argc < 2)
{
PrintHelp();
ILogSystem.Msg(LOG_LOW," · [LOG] - We need the .mpg video to play, try with \"VideoPlayer.exe your.mpg\"\n\n");
return 1;
}
// -CRM32Pro and SDL initialize-
if(CRM32Pro.Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER) < 0)
{
ILogSystem.Msg(LOG_NORMAL," · [LOG] - Couldnīt initialize CRM32Pro: %s\n",SDL_GetError());
return 1;
}
// -Desired config-
CRM32Pro.Config.Title = EXAMPLE_VERSION;
CRM32Pro.Config.Icon = IImage->Load(GFX_RESOURCE,"icono");
// Uncoment below two lines to use OpenGL renderer.
// By the way, it is not a good idea as each frame must be converted into a texture which is an intensive task
//CRM32Pro.Config.VideoRenderer = RENDER_OPENGL;
//CRM32Pro.Config.VideoAccel = ACCEL_HARDSMOOTH ;
// -Graphics system initialize-
if(!CRM32Pro.SetVideoMode())
{
CRM32Pro.Quit();
return 1;
}
// -Play MPEG-
IVideo->SetFunction(ChangeFX);
IVideo->PlayMPEG(argv[1],1);
// -Exiting..-
ILogSystem.Msg(LOG_NORMAL,"\n · [INFO]: end of execution.\n");
CRM32Pro.VideoInfo();
CRM32Pro.Quit();
return 0;
}
// Function to be called when a MPEG frame will be updated.
int ChangeFX(int kPressed,SDL_Surface *sFrame,SDL_Rect *rDst)
{
static int fx = FXSCREEN_NULL;
if(kPressed == SDLK_LEFT)
{
if(fx > 0) fx--;
IVideo->SetFX(fx);
}
else if(kPressed == SDLK_RIGHT)
{
if(fx < FXSCREEN_BLUE) fx++;
IVideo->SetFX(fx);
}
else if(kPressed == SDLK_s) // With "S" key, return 0 to stop the playback
{
return 0;
}
// With OpenGL video modes, we have to blit the frame on the screen
if(CRM32Pro.IsGL()) SDL_BlitSurface(sFrame,NULL,CRM32Pro.screen,rDst);
return 1;
}
// --------------------Help STUFF------------------------
// -Print help-
void PrintHelp(char *sErrMsg)
{
printf("-----------------------------------------------------------\n");
printf(" CRM32Pro SDK - HelpScreen\n %s\n",EXAMPLE_VERSION);
printf("-----------------------------------------------------------\n\n");
printf(" Use:\n");
printf(" - 'VideoPlayer your_video.mpg' to play the video.\n\n");
printf(" During the playback, you can use next keys:\n");
printf(" [ESCAPE] to abort and exit.\n");
printf(" [RIGHT CURSOR] to select the next FX effect.\n");
printf(" [LEFT CURSOR] to select the previous FX effect.\n");
if(sErrMsg != NULL) printf("%s",sErrMsg);
else printf("\n");
puts("Press [ENTER] key to continue.");
getchar();
}