- add a fallback url for playing videos in case the user has no internet

This commit is contained in:
Mark Vejvoda 2012-05-25 16:33:34 +00:00
parent 827f4fb89d
commit 660d702e97
7 changed files with 131 additions and 71 deletions

View File

@ -3729,7 +3729,8 @@ void Game::playStreamingVideo(const string &playVideo) {
videoPlayer = new Shared::Graphics::VideoPlayer(
&Renderer::getInstance(),
playVideo.c_str(),
playVideo,
"",
screen,
0,0,
screen->w,
@ -3753,7 +3754,8 @@ void Game::playStreamingVideo(const string &playVideo) {
videoPlayer = new Shared::Graphics::VideoPlayer(
&Renderer::getInstance(),
playVideo.c_str(),
playVideo,
"",
screen,
0,0,
screen->w,

View File

@ -408,6 +408,7 @@ void CoreData::load() {
Config &config= Config::getInstance();
introVideoFilename = config.getString("IntroVideoURL","");
introVideoFilenameFallback = config.getString("IntroVideoURLFallback","");
if(introVideoFilename == "") {
string introVideoPath = getGameCustomCoreDataPath(data_path, "") + "data/core/menu/videos/intro.*";
vector<string> introVideos;
@ -425,6 +426,7 @@ void CoreData::load() {
}
mainMenuVideoFilename = config.getString("MainMenuVideoURL","");
mainMenuVideoFilenameFallback = config.getString("MainMenuVideoURLFallback","");
if(mainMenuVideoFilename == "") {
string mainVideoPath = getGameCustomCoreDataPath(data_path, "") + "data/core/menu/videos/main.*";
vector<string> mainVideos;

View File

@ -89,7 +89,9 @@ private:
Font3D *consoleFont3D;
string introVideoFilename;
string introVideoFilenameFallback;
string mainMenuVideoFilename;
string mainMenuVideoFilenameFallback;
public:
@ -179,9 +181,13 @@ public:
string getMainMenuVideoFilename() const { return mainMenuVideoFilename; }
bool hasMainMenuVideoFilename() const;
string getMainMenuVideoFilenameFallback() const { return mainMenuVideoFilenameFallback; }
bool hasMainMenuVideoFilenameFallback() const;
string getIntroVideoFilename() const { return introVideoFilename; }
bool hasIntroVideoFilename() const;
string getIntroVideoFilenameFallback() const { return introVideoFilenameFallback; }
bool hasIntroVideoFilenameFallback() const;
void saveGameSettingsToFile(std::string fileName, GameSettings *gameSettings,int advancedIndex=0);
bool loadGameSettingsFromFile(std::string fileName, GameSettings *gameSettings);

View File

@ -497,32 +497,32 @@ Intro::Intro(Program *program):
Shared::Graphics::VideoPlayer::hasBackEndVideoPlayer() == true &&
CoreData::getInstance().hasIntroVideoFilename() == true) {
string introVideoFile = CoreData::getInstance().getIntroVideoFilename();
//if(fileExists(introVideoFile)) {
string introVideoFileFallback = CoreData::getInstance().getIntroVideoFilenameFallback();
renderer.clearBuffers();
renderer.reset3dMenu();
renderer.clearZBuffer();
renderer.reset2d();
//renderer.clearBuffers();
//renderer.reset3dMenu();
//renderer.clearZBuffer();
//renderer.reset2d();
Context *c= GraphicsInterface::getInstance().getCurrentContext();
SDL_Surface *screen = static_cast<ContextGl*>(c)->getPlatformContextGlPtr()->getScreen();
Context *c= GraphicsInterface::getInstance().getCurrentContext();
SDL_Surface *screen = static_cast<ContextGl*>(c)->getPlatformContextGlPtr()->getScreen();
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);
Shared::Graphics::VideoPlayer player(
&Renderer::getInstance(),
introVideoFile.c_str(),
screen,
0,0,
screen->w,
screen->h,
screen->format->BitsPerPixel,
vlcPluginsPath,
SystemFlags::VERBOSE_MODE_ENABLED);
player.PlayVideo();
exitAfterIntroVideo = true;
return;
//}
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);
Shared::Graphics::VideoPlayer player(
&Renderer::getInstance(),
introVideoFile,
introVideoFileFallback,
screen,
0,0,
screen->w,
screen->h,
screen->format->BitsPerPixel,
vlcPluginsPath,
SystemFlags::VERBOSE_MODE_ENABLED);
player.PlayVideo();
exitAfterIntroVideo = true;
return;
}
soundRenderer.playMusic(CoreData::getInstance().getIntroMusic());

View File

@ -99,24 +99,25 @@ void MainMenu::init() {
Shared::Graphics::VideoPlayer::hasBackEndVideoPlayer() == true &&
CoreData::getInstance().hasMainMenuVideoFilename() == true) {
string introVideoFile = CoreData::getInstance().getMainMenuVideoFilename();
//if(introVideoFile != "" && fileExists(introVideoFile)) {
Context *c= GraphicsInterface::getInstance().getCurrentContext();
SDL_Surface *screen = static_cast<ContextGl*>(c)->getPlatformContextGlPtr()->getScreen();
string introVideoFileFallback = CoreData::getInstance().getMainMenuVideoFilenameFallback();
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);
menuBackgroundVideo = new VideoPlayer(
&Renderer::getInstance(),
introVideoFile.c_str(),
screen,
0,0,
screen->w,
screen->h,
screen->format->BitsPerPixel,
vlcPluginsPath,
SystemFlags::VERBOSE_MODE_ENABLED);
menuBackgroundVideo->initPlayer();
//}
Context *c= GraphicsInterface::getInstance().getCurrentContext();
SDL_Surface *screen = static_cast<ContextGl*>(c)->getPlatformContextGlPtr()->getScreen();
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);
menuBackgroundVideo = new VideoPlayer(
&Renderer::getInstance(),
introVideoFile,
introVideoFileFallback,
screen,
0,0,
screen->w,
screen->h,
screen->format->BitsPerPixel,
vlcPluginsPath,
SystemFlags::VERBOSE_MODE_ENABLED);
menuBackgroundVideo->initPlayer();
}
}

View File

@ -30,6 +30,7 @@ class VideoPlayer {
protected:
string filename;
string filenameFallback;
SDL_Surface *surface;
int x;
int y;
@ -49,10 +50,16 @@ protected:
void init();
void cleanupPlayer();
bool initPlayer(string mediaURL);
public:
VideoPlayer(VideoLoadingCallbackInterface *loadingCB, string filename, SDL_Surface *surface, int x, int y,
int width, int height, int colorBits,
string pluginsPath,bool verboseEnabled=false);
VideoPlayer(VideoLoadingCallbackInterface *loadingCB,
string filename,
string filenameFallback,
SDL_Surface *surface, int x, int y,
int width, int height, int colorBits,
string pluginsPath,bool verboseEnabled=false);
virtual ~VideoPlayer();
void PlayVideo();

View File

@ -67,6 +67,9 @@ std::string getRegKey(const std::string& location, const std::string& name){
}
#endif
const string HTTP_PREFIX = "http";
const double MAX_VIDEO_START_MILLISECONDS = 10.0;
class ctx {
public:
ctx() {
@ -401,11 +404,15 @@ void callbacks( const libvlc_event_t* event, void* data ) {
#endif
VideoPlayer::VideoPlayer(VideoLoadingCallbackInterface *loadingCB, string filename, SDL_Surface *surface,
int x, int y,int width, int height,int colorBits,string pluginsPath,
bool verboseEnabled) : ctxPtr(NULL) {
VideoPlayer::VideoPlayer(VideoLoadingCallbackInterface *loadingCB,
string filename,
string filenameFallback,
SDL_Surface *surface,
int x, int y,int width, int height,int colorBits,
string pluginsPath, bool verboseEnabled) : ctxPtr(NULL) {
this->loadingCB = loadingCB;
this->filename = filename;
this->filenameFallback = filenameFallback;
this->surface = surface;
this->x = x;
this->y = y;
@ -434,6 +441,17 @@ void VideoPlayer::init() {
}
VideoPlayer::~VideoPlayer() {
cleanupPlayer();
}
bool VideoPlayer::hasBackEndVideoPlayer() {
#ifdef HAS_LIBVLC
return true;
#endif
return false;
}
void VideoPlayer::cleanupPlayer() {
if(ctxPtr != NULL) {
if(ctxPtr->rawData != NULL) {
free(ctxPtr->rawData);
@ -445,14 +463,7 @@ VideoPlayer::~VideoPlayer() {
}
}
bool VideoPlayer::hasBackEndVideoPlayer() {
#ifdef HAS_LIBVLC
return true;
#endif
return false;
}
bool VideoPlayer::initPlayer() {
bool VideoPlayer::initPlayer(string mediaURL) {
#ifdef HAS_LIBVLC
ctxPtr->libvlc = NULL;
ctxPtr->m = NULL;
@ -608,12 +619,9 @@ bool VideoPlayer::initPlayer() {
#endif
*/
const string HTTP_PREFIX = "http";
const double MAX_VIDEO_START_MILLISECONDS = 20.0;
if(ctxPtr->libvlc != NULL) {
#if defined(LIBVLC_VERSION_PRE_2) && defined(LIBVLC_VERSION_PRE_1_1_13)
ctxPtr->m = libvlc_media_new(ctxPtr->libvlc, filename.c_str(), &ex);
ctxPtr->m = libvlc_media_new(ctxPtr->libvlc, mediaURL.c_str(), &ex);
if(verboseEnabled) printf("In [%s] Line: %d, m [%p]\n",__FUNCTION__,__LINE__,ctxPtr->m);
catchError(&ex);
@ -622,23 +630,21 @@ bool VideoPlayer::initPlayer() {
libvlc_media_release(ctxPtr->m);
#else
if(filename.find(HTTP_PREFIX) == 0) {
if(mediaURL.find(HTTP_PREFIX) == 0) {
ctxPtr->mlp = libvlc_media_list_player_new(ctxPtr->libvlc);
ctxPtr->ml = libvlc_media_list_new(ctxPtr->libvlc);
ctxPtr->m = libvlc_media_new_location(ctxPtr->libvlc, filename.c_str());
ctxPtr->m = libvlc_media_new_location(ctxPtr->libvlc, mediaURL.c_str());
libvlc_media_list_add_media(ctxPtr->ml, ctxPtr->m);
}
else {
ctxPtr->m = libvlc_media_new_path(ctxPtr->libvlc, filename.c_str());
ctxPtr->m = libvlc_media_new_path(ctxPtr->libvlc, mediaURL.c_str());
}
/* Create a new item */
//ctxPtr->m = libvlc_media_new_path(ctxPtr->libvlc, filename.c_str());
//ctxPtr->m = libvlc_media_new_location(ctxPtr->libvlc, filename.c_str());
if(verboseEnabled) printf("In [%s] Line: %d, m [%p]\n",__FUNCTION__,__LINE__,ctxPtr->m);
if(filename.find(HTTP_PREFIX) == 0) {
if(mediaURL.find(HTTP_PREFIX) == 0) {
ctxPtr->mp = libvlc_media_player_new(ctxPtr->libvlc);
}
else {
@ -650,7 +656,7 @@ bool VideoPlayer::initPlayer() {
libvlc_media_release(ctxPtr->m);
if(filename.find(HTTP_PREFIX) == 0) {
if(mediaURL.find(HTTP_PREFIX) == 0) {
// Use our media list
libvlc_media_list_player_set_media_list(ctxPtr->mlp, ctxPtr->ml);
@ -659,7 +665,7 @@ bool VideoPlayer::initPlayer() {
}
// Get an event manager for the media player.
if(filename.find(HTTP_PREFIX) == 0) {
if(mediaURL.find(HTTP_PREFIX) == 0) {
libvlc_event_manager_t *eventManager = libvlc_media_list_player_event_manager(ctxPtr->mlp);
if(eventManager) {
@ -886,7 +892,7 @@ bool VideoPlayer::initPlayer() {
int play_result = libvlc_media_player_play(ctxPtr->mp,&ex);
#else
int play_result = 0;
if(filename.find(HTTP_PREFIX) == 0) {
if(mediaURL.find(HTTP_PREFIX) == 0) {
libvlc_media_list_player_play(ctxPtr->mlp);
}
else {
@ -902,6 +908,18 @@ bool VideoPlayer::initPlayer() {
successLoadingLib = (play_result == 0);
}
#endif
return successLoadingLib;
}
bool VideoPlayer::initPlayer() {
#ifdef HAS_LIBVLC
bool result = initPlayer(this->filename);
if(result == true) {
time_t waitStart = time(NULL);
for(;difftime(time(NULL),waitStart) <= MAX_VIDEO_START_MILLISECONDS &&
successLoadingLib == true &&
@ -916,9 +934,33 @@ bool VideoPlayer::initPlayer() {
}
SDL_Delay(1);
}
//SDL_Delay(5000);
}
if(isPlaying() == false && this->filenameFallback != "") {
closePlayer();
cleanupPlayer();
init();
result = initPlayer(this->filenameFallback);
if(result == true) {
time_t waitStart = time(NULL);
for(;difftime(time(NULL),waitStart) <= MAX_VIDEO_START_MILLISECONDS &&
successLoadingLib == true &&
(ctxPtr->error == false || ctxPtr->stopped == false) &&
ctxPtr->started == false;) {
if(ctxPtr->started == true) {
break;
}
if(this->loadingCB != NULL) {
int progress = ((difftime(time(NULL),waitStart) / MAX_VIDEO_START_MILLISECONDS) * 100.0);
this->loadingCB->renderVideoLoading(progress);
}
SDL_Delay(1);
}
}
}
#endif
return successLoadingLib;