- video player now displays 'please wait' while loading the video

This commit is contained in:
Mark Vejvoda 2012-05-23 19:59:52 +00:00
parent e61a17972e
commit 0fac755a5e
7 changed files with 112 additions and 34 deletions

View File

@ -1801,12 +1801,13 @@ int Game::getFirstUnusedTeamNumber() {
void Game::setupRenderForVideo() { void Game::setupRenderForVideo() {
Renderer &renderer= Renderer::getInstance(); Renderer &renderer= Renderer::getInstance();
renderer.clearBuffers(); //renderer.clearBuffers();
//3d //3d
renderer.reset3dMenu(); //renderer.reset3dMenu();
renderer.clearZBuffer(); //renderer.clearZBuffer();
//2d //2d
renderer.reset2d(); //renderer.reset2d();
renderer.setupRenderForVideo();
} }
void Game::tryPauseToggle(bool pauseValue) { void Game::tryPauseToggle(bool pauseValue) {
@ -3726,7 +3727,9 @@ void Game::playStreamingVideo(const string &playVideo) {
string vlcPluginsPath = Config::getInstance().getString("VideoPlayerPluginsPath",""); string vlcPluginsPath = Config::getInstance().getString("VideoPlayerPluginsPath","");
videoPlayer = new Shared::Graphics::VideoPlayer(playVideo.c_str(), videoPlayer = new Shared::Graphics::VideoPlayer(
&Renderer::getInstance(),
playVideo.c_str(),
screen, screen,
0,0, 0,0,
screen->w, screen->w,
@ -3748,7 +3751,9 @@ void Game::playStreamingVideo(const string &playVideo) {
string vlcPluginsPath = Config::getInstance().getString("VideoPlayerPluginsPath",""); string vlcPluginsPath = Config::getInstance().getString("VideoPlayerPluginsPath","");
videoPlayer = new Shared::Graphics::VideoPlayer(playVideo.c_str(), videoPlayer = new Shared::Graphics::VideoPlayer(
&Renderer::getInstance(),
playVideo.c_str(),
screen, screen,
0,0, 0,0,
screen->w, screen->w,

View File

@ -8533,4 +8533,47 @@ void Renderer::renderPopupMenu(PopupMenu *menu) {
} }
void Renderer::setupRenderForVideo() {
clearBuffers();
//3d
reset3dMenu();
clearZBuffer();
//2d
reset2d();
glClearColor(0.f, 0.f, 0.f, 1.f);
}
void Renderer::renderVideoLoading(int progressPercent) {
//printf("Rendering progress progressPercent = %d\n",progressPercent);
setupRenderForVideo();
Lang &lang= Lang::getInstance();
string textToRender = lang.get("PleaseWait");
const Metrics &metrics= Metrics::getInstance();
if(CoreData::getInstance().getMenuFontBig3D() != NULL) {
int renderX = 0;
int renderY = 0;
int w= metrics.getVirtualW();
renderX = (w / 2) - (CoreData::getInstance().getMenuFontBig3D()->getMetrics()->getTextWidth(textToRender) / 2);
int h= metrics.getVirtualH();
renderY = (h / 2) + (CoreData::getInstance().getMenuFontBig3D()->getMetrics()->getHeight(textToRender) / 2);
renderText3D(
textToRender,
CoreData::getInstance().getMenuFontBig3D(),
Vec3f(1.f, 1.f, 0.f),
renderX, renderY, false);
}
else {
renderText(
textToRender,
CoreData::getInstance().getMenuFontBig(),
Vec3f(1.f, 1.f, 0.f), (metrics.getScreenW() / 2),
(metrics.getScreenH() / 2), true);
}
swapBuffers();
}
}}//end namespace }}//end namespace

View File

@ -37,6 +37,7 @@
#include "graphics_interface.h" #include "graphics_interface.h"
#include "base_renderer.h" #include "base_renderer.h"
#include "simple_threads.h" #include "simple_threads.h"
#include "video_player.h"
#ifdef DEBUG_RENDERING_ENABLED #ifdef DEBUG_RENDERING_ENABLED
# define IF_DEBUG_EDITION(x) x # define IF_DEBUG_EDITION(x) x
@ -179,7 +180,8 @@ public:
class Renderer : public RendererInterface, class Renderer : public RendererInterface,
public BaseRenderer, public BaseRenderer,
// This is for screen saver thread // This is for screen saver thread
public SimpleTaskCallbackInterface { public SimpleTaskCallbackInterface,
public VideoLoadingCallbackInterface {
public: public:
//progress bar //progress bar
static const int maxProgressBar; static const int maxProgressBar;
@ -591,6 +593,9 @@ public:
void setProgram(Program *program) { this->program = program; } void setProgram(Program *program) { this->program = program; }
void setupRenderForVideo();
virtual void renderVideoLoading(int progressPercent);
private: private:
//private misc //private misc
float computeSunAngle(float time); float computeSunAngle(float time);

View File

@ -498,14 +498,22 @@ Intro::Intro(Program *program):
CoreData::getInstance().hasIntroVideoFilename() == true) { CoreData::getInstance().hasIntroVideoFilename() == true) {
string introVideoFile = CoreData::getInstance().getIntroVideoFilename(); string introVideoFile = CoreData::getInstance().getIntroVideoFilename();
//if(fileExists(introVideoFile)) { //if(fileExists(introVideoFile)) {
renderer.clearBuffers();
renderer.reset3dMenu();
renderer.clearZBuffer();
renderer.reset2d();
Context *c= GraphicsInterface::getInstance().getCurrentContext(); Context *c= GraphicsInterface::getInstance().getCurrentContext();
SDL_Surface *screen = static_cast<ContextGl*>(c)->getPlatformContextGlPtr()->getScreen(); SDL_Surface *screen = static_cast<ContextGl*>(c)->getPlatformContextGlPtr()->getScreen();
string vlcPluginsPath = Config::getInstance().getString("VideoPlayerPluginsPath",""); string vlcPluginsPath = Config::getInstance().getString("VideoPlayerPluginsPath","");
//printf("screen->w = %d screen->h = %d screen->format->BitsPerPixel = %d\n",screen->w,screen->h,screen->format->BitsPerPixel); //printf("screen->w = %d screen->h = %d screen->format->BitsPerPixel = %d\n",screen->w,screen->h,screen->format->BitsPerPixel);
Shared::Graphics::VideoPlayer player(introVideoFile.c_str(), Shared::Graphics::VideoPlayer player(
&Renderer::getInstance(),
introVideoFile.c_str(),
screen, screen,
-1,-1, 0,0,
screen->w, screen->w,
screen->h, screen->h,
screen->format->BitsPerPixel, screen->format->BitsPerPixel,

View File

@ -105,7 +105,9 @@ void MainMenu::init() {
string vlcPluginsPath = Config::getInstance().getString("VideoPlayerPluginsPath",""); string vlcPluginsPath = Config::getInstance().getString("VideoPlayerPluginsPath","");
//printf("screen->w = %d screen->h = %d screen->format->BitsPerPixel = %d\n",screen->w,screen->h,screen->format->BitsPerPixel); //printf("screen->w = %d screen->h = %d screen->format->BitsPerPixel = %d\n",screen->w,screen->h,screen->format->BitsPerPixel);
menuBackgroundVideo = new VideoPlayer(introVideoFile.c_str(), menuBackgroundVideo = new VideoPlayer(
&Renderer::getInstance(),
introVideoFile.c_str(),
screen, screen,
0,0, 0,0,
screen->w, screen->w,

View File

@ -20,6 +20,12 @@ using namespace std;
namespace Shared{ namespace Graphics{ namespace Shared{ namespace Graphics{
class VideoLoadingCallbackInterface {
public:
/** a value from 1 to 100 representing % done */
virtual void renderVideoLoading(int progressPercent) = 0;
};
class VideoPlayer { class VideoPlayer {
protected: protected:
@ -38,12 +44,13 @@ protected:
bool stop; bool stop;
bool finished; bool finished;
VideoLoadingCallbackInterface *loadingCB;
ctx *ctxPtr; ctx *ctxPtr;
void init(); void init();
public: public:
VideoPlayer(string filename, SDL_Surface *surface, int x, int y, VideoPlayer(VideoLoadingCallbackInterface *loadingCB, string filename, SDL_Surface *surface, int x, int y,
int width, int height, int colorBits, int width, int height, int colorBits,
string pluginsPath,bool verboseEnabled=false); string pluginsPath,bool verboseEnabled=false);
virtual ~VideoPlayer(); virtual ~VideoPlayer();

View File

@ -70,6 +70,7 @@ std::string getRegKey(const std::string& location, const std::string& name){
class ctx { class ctx {
public: public:
ctx() { ctx() {
loadingCB = NULL;
empty = NULL; empty = NULL;
textureId = 0; // Texture ID textureId = 0; // Texture ID
surf = NULL; surf = NULL;
@ -99,6 +100,7 @@ public:
#endif #endif
} }
Shared::Graphics::VideoLoadingCallbackInterface *loadingCB;
SDL_Surface *empty; SDL_Surface *empty;
GLuint textureId; // Texture ID GLuint textureId; // Texture ID
SDL_Surface *surf; SDL_Surface *surf;
@ -399,9 +401,10 @@ void callbacks( const libvlc_event_t* event, void* data ) {
#endif #endif
VideoPlayer::VideoPlayer(string filename, SDL_Surface *surface, VideoPlayer::VideoPlayer(VideoLoadingCallbackInterface *loadingCB, string filename, SDL_Surface *surface,
int x, int y,int width, int height,int colorBits,string pluginsPath, int x, int y,int width, int height,int colorBits,string pluginsPath,
bool verboseEnabled) : ctxPtr(NULL) { bool verboseEnabled) : ctxPtr(NULL) {
this->loadingCB = loadingCB;
this->filename = filename; this->filename = filename;
this->surface = surface; this->surface = surface;
this->x = x; this->x = x;
@ -421,6 +424,7 @@ VideoPlayer::VideoPlayer(string filename, SDL_Surface *surface,
void VideoPlayer::init() { void VideoPlayer::init() {
ctxPtr = new ctx(); ctxPtr = new ctx();
ctxPtr->loadingCB = loadingCB;
ctxPtr->x = x; ctxPtr->x = x;
ctxPtr->y = y; ctxPtr->y = y;
ctxPtr->width = width; ctxPtr->width = width;
@ -605,7 +609,7 @@ bool VideoPlayer::initPlayer() {
*/ */
const string HTTP_PREFIX = "http"; const string HTTP_PREFIX = "http";
const double MAX_VIDEO_START_MILLISECONDS = 20; const double MAX_VIDEO_START_MILLISECONDS = 20.0;
if(ctxPtr->libvlc != NULL) { if(ctxPtr->libvlc != NULL) {
#if defined(LIBVLC_VERSION_PRE_2) && defined(LIBVLC_VERSION_PRE_1_1_13) #if defined(LIBVLC_VERSION_PRE_2) && defined(LIBVLC_VERSION_PRE_1_1_13)
@ -906,7 +910,11 @@ bool VideoPlayer::initPlayer() {
if(ctxPtr->started == true) { if(ctxPtr->started == true) {
break; break;
} }
SDL_Delay(10); if(this->loadingCB != NULL) {
int progress = ((difftime(time(NULL),waitStart) / MAX_VIDEO_START_MILLISECONDS) * 100.0);
this->loadingCB->renderVideoLoading(progress);
}
SDL_Delay(1);
} }
//SDL_Delay(5000); //SDL_Delay(5000);