SDL play two video

Started by
4 comments, last by mangshe0 15 years, 5 months ago
Hi I use SDL SMPEG, play two video. if ( SDL_Init(SDL_INIT_AUDIO|SDL_INIT_VIDEO) < 0 ) { printf("Unable to init SDL: %s\n", SDL_GetError()); return -1; } screen = SDL_SetVideoMode( 1024, 768, 32,SDL_HWSURFACE );//|SDL_FULLSCREEN if ( screen == NULL ) { printf("Unable to set 1024x768 video: %s\n", SDL_GetError()); return -1; } // Load the movie and store the information about it movie = SMPEG_new( "4.mpg", &moveInfo, true ); movie2 = SMPEG_new( "2.mpg", &moveInfo2, true ); char* error = SMPEG_error( movie ); if( error ) { printf( "Error loading MPEG: %s\n", error ); return -1; } char* error2 = SMPEG_error( movie2 ); if( error ) { printf( "Error loading MPEG: %s\n", error ); return -1; } but it show Error loading MPEG: Audio device is already opened if i donot write error2, when play first video is very slowly,and two video donot to play. How to play two video? thank you thank you very muuch
Advertisement
code:

#include "SDL/sdl.h"
#include "SDL/smpeg.h"

#pragma comment( lib, "smpeg.lib")
//SDL.lib SDLmain.lib SDL_image.lib SDL_ttf.lib SDL_mixer.lib smpeg.lib
// Surface for the main screen
SDL_Surface *screen;

// Surface for the movie
SDL_Surface *movieSurface = 0;
SDL_Surface *movieSurface2 = 0;
SDL_Surface *movieSurface3 = 0;
// Holds the movie information
SMPEG_Info moveInfo;
SMPEG_Info moveInfo2;
SMPEG_Info moveInfo3;
// Load the movie
SMPEG *movie = 0;
SMPEG *movie2 = 0;
SMPEG *movie3 = 0;

void DrawIMG(SDL_Surface *img, int x, int y)
{
SDL_Rect dest;
dest.x = x;
dest.y = y;
SDL_BlitSurface(img, NULL, screen, &dest);
}



int main(int argc, char *argv[])
{
if ( SDL_Init(SDL_INIT_AUDIO|SDL_INIT_VIDEO) < 0 )
{
printf("Unable to init SDL: %s\n", SDL_GetError());
return -1;
}

screen = SDL_SetVideoMode( 1024, 768, 32, SDL_HWSURFACE );//|SDL_FULLSCREEN
if ( screen == NULL )
{
printf("Unable to set 640x480 video: %s\n", SDL_GetError());
return -1;
}

// Load the movie and store the information about it
movie = SMPEG_new( "4.mpg", &moveInfo, true );
movie2 = SMPEG_new( "2.mpg", &moveInfo2, true );
movie3 = SMPEG_new( "3.mpg", &moveInfo3, true );

char* error = SMPEG_error( movie );
if( error )
{
printf( "Error loading MPEG: %s\n", error );
return -1;
}
char* error2 = SMPEG_error( movie2 );
if( error )
{
printf( "Error loading MPEG: %s\n", error );
return -1;
}

// Create a temporary surface to render the movie to
SDL_Surface *tempSurface2 = SDL_CreateRGBSurface( SDL_SWSURFACE, moveInfo.width, moveInfo.height, 32,
screen->format->Rmask, screen->format->Gmask, screen->format->Bmask, screen->format->Amask );
//Rmask Gmask Bmask RGB 红绿蓝 Amask alpha 透明度
SDL_Surface *tempSurface3 = SDL_CreateRGBSurface( SDL_SWSURFACE, moveInfo2.width, moveInfo2.height, 32,
screen->format->Rmask, screen->format->Gmask, screen->format->Bmask, screen->format->Amask );
SDL_Surface *tempSurface4 = SDL_CreateRGBSurface( SDL_SWSURFACE, moveInfo3.width, moveInfo3.height, 32,
screen->format->Rmask, screen->format->Gmask, screen->format->Bmask, screen->format->Amask );
// SDL_BlitSurface(tempSurface2, NULL, screen, &dest); //位块移动 将源的内存块 移动到目标位置 前2个参数是源 后2是目标
// Now make a surface optimized for the main screen
movieSurface = SDL_DisplayFormat( tempSurface2 );
movieSurface2 = SDL_DisplayFormat( tempSurface3 );
movieSurface3 = SDL_DisplayFormat( tempSurface4 );
// SDL_BlitSurface(movieSurface, &dest2, screen, &dest); //位块移动 将源的内存块 移动到目标位置 前2个参数是源 后2是目标

//Free the temporary surface
SDL_FreeSurface( tempSurface2 );
SDL_FreeSurface( tempSurface3 );
SDL_FreeSurface( tempSurface4 );

// Set the surface to draw to
SMPEG_setdisplay( movie, movieSurface, 0, 0 ); // screen movieSurface
SMPEG_setdisplay( movie2, movieSurface2, 0, 0 );
SMPEG_setdisplay( movie3, movieSurface3, 0, 0 );

// Set the display region
SMPEG_setdisplayregion( movie, 0, 0,moveInfo.width, moveInfo.height);
SMPEG_setdisplayregion( movie2, 0, 0,moveInfo2.width, moveInfo2.height);
SMPEG_setdisplayregion( movie3, 0, 0,moveInfo3.width, moveInfo3.height);

//s SMPEG_move(movie,50,50);
// DrawIMG(movieSurface,100,100);

// SDL_BlitSurface(movieSurface, NULL, screen, &dest); //位块移动 将源的内存块 移动到目标位置 前2个参数是源 后2是目标

// Loop forever renderFrame
SMPEG_loop( movie, -1 );
SMPEG_loop( movie2, -1 );
SMPEG_loop( movie3, -1 );

SDL_ShowCursor(SDL_DISABLE);

int done=0;

while(done == 0)
{
SDL_Event event;

while ( SDL_PollEvent(&event) )
{
if ( event.type == SDL_QUIT ) { done = 1; }

if ( event.type == SDL_KEYDOWN )
{
if ( event.key.keysym.sym == SDLK_ESCAPE ) { done = 1; }
}
}

// Play the movie
SMPEG_play( movie );
SMPEG_play( movie2 );
SMPEG_play( movie3 );
// SMPEG_move(movie,50,50);
// Draw the movie surface to the main screen at 0,0
DrawIMG( movieSurface, 0, 0 ); //能够移动movieSurface框架
DrawIMG( movieSurface2, 450, 150 ); //能够移动movieSurface框架
DrawIMG( movieSurface3, 600, 500 ); //能够移动movieSurface框架

// Flip the main screen
SDL_Flip( screen );
}

SDL_FreeSurface(movieSurface);
SDL_FreeSurface(movieSurface2);
SDL_FreeSurface(movieSurface3);
// SDL_FreeSurface( tempSurface2 );
SMPEG_stop(movie);
SMPEG_stop(movie2);
SMPEG_stop(movie3);
SMPEG_delete(movie);
SMPEG_delete(movie2);
SMPEG_delete(movie3);
movie = NULL;
movie2 = NULL;
movie3 = NULL;
SDL_ShowCursor(SDL_ENABLE);

// printf( "MPEG with and height: %s\n", moveInfo.width, moveInfo.height );
return 0;
}


mark! how to play two video.
Mark!

mark
if SDL SMPEG can not achieve, please tell me,let me Give up hope.
thank you.
beacuse DriectXShow can play two video.

This topic is closed to new replies.

Advertisement