- add a fallback url for playing videos in case the user has no internet
This commit is contained in:
parent
827f4fb89d
commit
660d702e97
|
@ -3729,7 +3729,8 @@ void Game::playStreamingVideo(const string &playVideo) {
|
||||||
|
|
||||||
videoPlayer = new Shared::Graphics::VideoPlayer(
|
videoPlayer = new Shared::Graphics::VideoPlayer(
|
||||||
&Renderer::getInstance(),
|
&Renderer::getInstance(),
|
||||||
playVideo.c_str(),
|
playVideo,
|
||||||
|
"",
|
||||||
screen,
|
screen,
|
||||||
0,0,
|
0,0,
|
||||||
screen->w,
|
screen->w,
|
||||||
|
@ -3753,7 +3754,8 @@ void Game::playStreamingVideo(const string &playVideo) {
|
||||||
|
|
||||||
videoPlayer = new Shared::Graphics::VideoPlayer(
|
videoPlayer = new Shared::Graphics::VideoPlayer(
|
||||||
&Renderer::getInstance(),
|
&Renderer::getInstance(),
|
||||||
playVideo.c_str(),
|
playVideo,
|
||||||
|
"",
|
||||||
screen,
|
screen,
|
||||||
0,0,
|
0,0,
|
||||||
screen->w,
|
screen->w,
|
||||||
|
|
|
@ -408,6 +408,7 @@ void CoreData::load() {
|
||||||
Config &config= Config::getInstance();
|
Config &config= Config::getInstance();
|
||||||
|
|
||||||
introVideoFilename = config.getString("IntroVideoURL","");
|
introVideoFilename = config.getString("IntroVideoURL","");
|
||||||
|
introVideoFilenameFallback = config.getString("IntroVideoURLFallback","");
|
||||||
if(introVideoFilename == "") {
|
if(introVideoFilename == "") {
|
||||||
string introVideoPath = getGameCustomCoreDataPath(data_path, "") + "data/core/menu/videos/intro.*";
|
string introVideoPath = getGameCustomCoreDataPath(data_path, "") + "data/core/menu/videos/intro.*";
|
||||||
vector<string> introVideos;
|
vector<string> introVideos;
|
||||||
|
@ -425,6 +426,7 @@ void CoreData::load() {
|
||||||
}
|
}
|
||||||
|
|
||||||
mainMenuVideoFilename = config.getString("MainMenuVideoURL","");
|
mainMenuVideoFilename = config.getString("MainMenuVideoURL","");
|
||||||
|
mainMenuVideoFilenameFallback = config.getString("MainMenuVideoURLFallback","");
|
||||||
if(mainMenuVideoFilename == "") {
|
if(mainMenuVideoFilename == "") {
|
||||||
string mainVideoPath = getGameCustomCoreDataPath(data_path, "") + "data/core/menu/videos/main.*";
|
string mainVideoPath = getGameCustomCoreDataPath(data_path, "") + "data/core/menu/videos/main.*";
|
||||||
vector<string> mainVideos;
|
vector<string> mainVideos;
|
||||||
|
|
|
@ -89,7 +89,9 @@ private:
|
||||||
Font3D *consoleFont3D;
|
Font3D *consoleFont3D;
|
||||||
|
|
||||||
string introVideoFilename;
|
string introVideoFilename;
|
||||||
|
string introVideoFilenameFallback;
|
||||||
string mainMenuVideoFilename;
|
string mainMenuVideoFilename;
|
||||||
|
string mainMenuVideoFilenameFallback;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@ -179,9 +181,13 @@ public:
|
||||||
|
|
||||||
string getMainMenuVideoFilename() const { return mainMenuVideoFilename; }
|
string getMainMenuVideoFilename() const { return mainMenuVideoFilename; }
|
||||||
bool hasMainMenuVideoFilename() const;
|
bool hasMainMenuVideoFilename() const;
|
||||||
|
string getMainMenuVideoFilenameFallback() const { return mainMenuVideoFilenameFallback; }
|
||||||
|
bool hasMainMenuVideoFilenameFallback() const;
|
||||||
|
|
||||||
string getIntroVideoFilename() const { return introVideoFilename; }
|
string getIntroVideoFilename() const { return introVideoFilename; }
|
||||||
bool hasIntroVideoFilename() const;
|
bool hasIntroVideoFilename() const;
|
||||||
|
string getIntroVideoFilenameFallback() const { return introVideoFilenameFallback; }
|
||||||
|
bool hasIntroVideoFilenameFallback() const;
|
||||||
|
|
||||||
void saveGameSettingsToFile(std::string fileName, GameSettings *gameSettings,int advancedIndex=0);
|
void saveGameSettingsToFile(std::string fileName, GameSettings *gameSettings,int advancedIndex=0);
|
||||||
bool loadGameSettingsFromFile(std::string fileName, GameSettings *gameSettings);
|
bool loadGameSettingsFromFile(std::string fileName, GameSettings *gameSettings);
|
||||||
|
|
|
@ -497,32 +497,32 @@ Intro::Intro(Program *program):
|
||||||
Shared::Graphics::VideoPlayer::hasBackEndVideoPlayer() == true &&
|
Shared::Graphics::VideoPlayer::hasBackEndVideoPlayer() == true &&
|
||||||
CoreData::getInstance().hasIntroVideoFilename() == true) {
|
CoreData::getInstance().hasIntroVideoFilename() == true) {
|
||||||
string introVideoFile = CoreData::getInstance().getIntroVideoFilename();
|
string introVideoFile = CoreData::getInstance().getIntroVideoFilename();
|
||||||
//if(fileExists(introVideoFile)) {
|
string introVideoFileFallback = CoreData::getInstance().getIntroVideoFilenameFallback();
|
||||||
|
|
||||||
renderer.clearBuffers();
|
//renderer.clearBuffers();
|
||||||
renderer.reset3dMenu();
|
//renderer.reset3dMenu();
|
||||||
renderer.clearZBuffer();
|
//renderer.clearZBuffer();
|
||||||
renderer.reset2d();
|
//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(
|
Shared::Graphics::VideoPlayer player(
|
||||||
&Renderer::getInstance(),
|
&Renderer::getInstance(),
|
||||||
introVideoFile.c_str(),
|
introVideoFile,
|
||||||
screen,
|
introVideoFileFallback,
|
||||||
0,0,
|
screen,
|
||||||
screen->w,
|
0,0,
|
||||||
screen->h,
|
screen->w,
|
||||||
screen->format->BitsPerPixel,
|
screen->h,
|
||||||
vlcPluginsPath,
|
screen->format->BitsPerPixel,
|
||||||
SystemFlags::VERBOSE_MODE_ENABLED);
|
vlcPluginsPath,
|
||||||
player.PlayVideo();
|
SystemFlags::VERBOSE_MODE_ENABLED);
|
||||||
exitAfterIntroVideo = true;
|
player.PlayVideo();
|
||||||
return;
|
exitAfterIntroVideo = true;
|
||||||
//}
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
soundRenderer.playMusic(CoreData::getInstance().getIntroMusic());
|
soundRenderer.playMusic(CoreData::getInstance().getIntroMusic());
|
||||||
|
|
|
@ -99,24 +99,25 @@ void MainMenu::init() {
|
||||||
Shared::Graphics::VideoPlayer::hasBackEndVideoPlayer() == true &&
|
Shared::Graphics::VideoPlayer::hasBackEndVideoPlayer() == true &&
|
||||||
CoreData::getInstance().hasMainMenuVideoFilename() == true) {
|
CoreData::getInstance().hasMainMenuVideoFilename() == true) {
|
||||||
string introVideoFile = CoreData::getInstance().getMainMenuVideoFilename();
|
string introVideoFile = CoreData::getInstance().getMainMenuVideoFilename();
|
||||||
//if(introVideoFile != "" && fileExists(introVideoFile)) {
|
string introVideoFileFallback = CoreData::getInstance().getMainMenuVideoFilenameFallback();
|
||||||
Context *c= GraphicsInterface::getInstance().getCurrentContext();
|
|
||||||
SDL_Surface *screen = static_cast<ContextGl*>(c)->getPlatformContextGlPtr()->getScreen();
|
|
||||||
|
|
||||||
string vlcPluginsPath = Config::getInstance().getString("VideoPlayerPluginsPath","");
|
Context *c= GraphicsInterface::getInstance().getCurrentContext();
|
||||||
//printf("screen->w = %d screen->h = %d screen->format->BitsPerPixel = %d\n",screen->w,screen->h,screen->format->BitsPerPixel);
|
SDL_Surface *screen = static_cast<ContextGl*>(c)->getPlatformContextGlPtr()->getScreen();
|
||||||
menuBackgroundVideo = new VideoPlayer(
|
|
||||||
&Renderer::getInstance(),
|
string vlcPluginsPath = Config::getInstance().getString("VideoPlayerPluginsPath","");
|
||||||
introVideoFile.c_str(),
|
//printf("screen->w = %d screen->h = %d screen->format->BitsPerPixel = %d\n",screen->w,screen->h,screen->format->BitsPerPixel);
|
||||||
screen,
|
menuBackgroundVideo = new VideoPlayer(
|
||||||
0,0,
|
&Renderer::getInstance(),
|
||||||
screen->w,
|
introVideoFile,
|
||||||
screen->h,
|
introVideoFileFallback,
|
||||||
screen->format->BitsPerPixel,
|
screen,
|
||||||
vlcPluginsPath,
|
0,0,
|
||||||
SystemFlags::VERBOSE_MODE_ENABLED);
|
screen->w,
|
||||||
menuBackgroundVideo->initPlayer();
|
screen->h,
|
||||||
//}
|
screen->format->BitsPerPixel,
|
||||||
|
vlcPluginsPath,
|
||||||
|
SystemFlags::VERBOSE_MODE_ENABLED);
|
||||||
|
menuBackgroundVideo->initPlayer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,7 @@ class VideoPlayer {
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
string filename;
|
string filename;
|
||||||
|
string filenameFallback;
|
||||||
SDL_Surface *surface;
|
SDL_Surface *surface;
|
||||||
int x;
|
int x;
|
||||||
int y;
|
int y;
|
||||||
|
@ -49,10 +50,16 @@ protected:
|
||||||
|
|
||||||
void init();
|
void init();
|
||||||
|
|
||||||
|
void cleanupPlayer();
|
||||||
|
bool initPlayer(string mediaURL);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
VideoPlayer(VideoLoadingCallbackInterface *loadingCB, string filename, SDL_Surface *surface, int x, int y,
|
VideoPlayer(VideoLoadingCallbackInterface *loadingCB,
|
||||||
int width, int height, int colorBits,
|
string filename,
|
||||||
string pluginsPath,bool verboseEnabled=false);
|
string filenameFallback,
|
||||||
|
SDL_Surface *surface, int x, int y,
|
||||||
|
int width, int height, int colorBits,
|
||||||
|
string pluginsPath,bool verboseEnabled=false);
|
||||||
virtual ~VideoPlayer();
|
virtual ~VideoPlayer();
|
||||||
|
|
||||||
void PlayVideo();
|
void PlayVideo();
|
||||||
|
|
|
@ -67,6 +67,9 @@ std::string getRegKey(const std::string& location, const std::string& name){
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
const string HTTP_PREFIX = "http";
|
||||||
|
const double MAX_VIDEO_START_MILLISECONDS = 10.0;
|
||||||
|
|
||||||
class ctx {
|
class ctx {
|
||||||
public:
|
public:
|
||||||
ctx() {
|
ctx() {
|
||||||
|
@ -401,11 +404,15 @@ void callbacks( const libvlc_event_t* event, void* data ) {
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
VideoPlayer::VideoPlayer(VideoLoadingCallbackInterface *loadingCB, string filename, SDL_Surface *surface,
|
VideoPlayer::VideoPlayer(VideoLoadingCallbackInterface *loadingCB,
|
||||||
int x, int y,int width, int height,int colorBits,string pluginsPath,
|
string filename,
|
||||||
bool verboseEnabled) : ctxPtr(NULL) {
|
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->loadingCB = loadingCB;
|
||||||
this->filename = filename;
|
this->filename = filename;
|
||||||
|
this->filenameFallback = filenameFallback;
|
||||||
this->surface = surface;
|
this->surface = surface;
|
||||||
this->x = x;
|
this->x = x;
|
||||||
this->y = y;
|
this->y = y;
|
||||||
|
@ -434,6 +441,17 @@ void VideoPlayer::init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
VideoPlayer::~VideoPlayer() {
|
VideoPlayer::~VideoPlayer() {
|
||||||
|
cleanupPlayer();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool VideoPlayer::hasBackEndVideoPlayer() {
|
||||||
|
#ifdef HAS_LIBVLC
|
||||||
|
return true;
|
||||||
|
#endif
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void VideoPlayer::cleanupPlayer() {
|
||||||
if(ctxPtr != NULL) {
|
if(ctxPtr != NULL) {
|
||||||
if(ctxPtr->rawData != NULL) {
|
if(ctxPtr->rawData != NULL) {
|
||||||
free(ctxPtr->rawData);
|
free(ctxPtr->rawData);
|
||||||
|
@ -445,14 +463,7 @@ VideoPlayer::~VideoPlayer() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool VideoPlayer::hasBackEndVideoPlayer() {
|
bool VideoPlayer::initPlayer(string mediaURL) {
|
||||||
#ifdef HAS_LIBVLC
|
|
||||||
return true;
|
|
||||||
#endif
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool VideoPlayer::initPlayer() {
|
|
||||||
#ifdef HAS_LIBVLC
|
#ifdef HAS_LIBVLC
|
||||||
ctxPtr->libvlc = NULL;
|
ctxPtr->libvlc = NULL;
|
||||||
ctxPtr->m = NULL;
|
ctxPtr->m = NULL;
|
||||||
|
@ -608,12 +619,9 @@ bool VideoPlayer::initPlayer() {
|
||||||
#endif
|
#endif
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const string HTTP_PREFIX = "http";
|
|
||||||
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)
|
||||||
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);
|
if(verboseEnabled) printf("In [%s] Line: %d, m [%p]\n",__FUNCTION__,__LINE__,ctxPtr->m);
|
||||||
|
|
||||||
catchError(&ex);
|
catchError(&ex);
|
||||||
|
@ -622,23 +630,21 @@ bool VideoPlayer::initPlayer() {
|
||||||
|
|
||||||
libvlc_media_release(ctxPtr->m);
|
libvlc_media_release(ctxPtr->m);
|
||||||
#else
|
#else
|
||||||
if(filename.find(HTTP_PREFIX) == 0) {
|
if(mediaURL.find(HTTP_PREFIX) == 0) {
|
||||||
ctxPtr->mlp = libvlc_media_list_player_new(ctxPtr->libvlc);
|
ctxPtr->mlp = libvlc_media_list_player_new(ctxPtr->libvlc);
|
||||||
ctxPtr->ml = libvlc_media_list_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);
|
libvlc_media_list_add_media(ctxPtr->ml, ctxPtr->m);
|
||||||
}
|
}
|
||||||
else {
|
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 */
|
/* 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(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);
|
ctxPtr->mp = libvlc_media_player_new(ctxPtr->libvlc);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -650,7 +656,7 @@ bool VideoPlayer::initPlayer() {
|
||||||
|
|
||||||
libvlc_media_release(ctxPtr->m);
|
libvlc_media_release(ctxPtr->m);
|
||||||
|
|
||||||
if(filename.find(HTTP_PREFIX) == 0) {
|
if(mediaURL.find(HTTP_PREFIX) == 0) {
|
||||||
// Use our media list
|
// Use our media list
|
||||||
libvlc_media_list_player_set_media_list(ctxPtr->mlp, ctxPtr->ml);
|
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.
|
// 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);
|
libvlc_event_manager_t *eventManager = libvlc_media_list_player_event_manager(ctxPtr->mlp);
|
||||||
|
|
||||||
if(eventManager) {
|
if(eventManager) {
|
||||||
|
@ -886,7 +892,7 @@ bool VideoPlayer::initPlayer() {
|
||||||
int play_result = libvlc_media_player_play(ctxPtr->mp,&ex);
|
int play_result = libvlc_media_player_play(ctxPtr->mp,&ex);
|
||||||
#else
|
#else
|
||||||
int play_result = 0;
|
int play_result = 0;
|
||||||
if(filename.find(HTTP_PREFIX) == 0) {
|
if(mediaURL.find(HTTP_PREFIX) == 0) {
|
||||||
libvlc_media_list_player_play(ctxPtr->mlp);
|
libvlc_media_list_player_play(ctxPtr->mlp);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -902,6 +908,18 @@ bool VideoPlayer::initPlayer() {
|
||||||
|
|
||||||
successLoadingLib = (play_result == 0);
|
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);
|
time_t waitStart = time(NULL);
|
||||||
for(;difftime(time(NULL),waitStart) <= MAX_VIDEO_START_MILLISECONDS &&
|
for(;difftime(time(NULL),waitStart) <= MAX_VIDEO_START_MILLISECONDS &&
|
||||||
successLoadingLib == true &&
|
successLoadingLib == true &&
|
||||||
|
@ -916,9 +934,33 @@ bool VideoPlayer::initPlayer() {
|
||||||
}
|
}
|
||||||
SDL_Delay(1);
|
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
|
#endif
|
||||||
|
|
||||||
return successLoadingLib;
|
return successLoadingLib;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user