From c33c1826ae9db816a0adfe5a5c0add1b6c9d8245 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Thu, 27 Sep 2012 01:17:57 +0000 Subject: [PATCH] - proper implementation of video repeat (looping) --- source/glest_game/game/game.cpp | 2 ++ source/glest_game/main/battle_end.cpp | 1 + source/glest_game/main/intro.cpp | 1 + source/glest_game/menu/main_menu.cpp | 1 + .../menu/menu_state_connected_game.cpp | 1 + .../menu/menu_state_custom_game.cpp | 1 + .../include/graphics/video_player.h | 3 +- .../sources/graphics/video_player.cpp | 29 ++++++++++++++++++- 8 files changed, 37 insertions(+), 2 deletions(-) diff --git a/source/glest_game/game/game.cpp b/source/glest_game/game/game.cpp index 939fe7050..07202fc92 100644 --- a/source/glest_game/game/game.cpp +++ b/source/glest_game/game/game.cpp @@ -4571,6 +4571,7 @@ void Game::playStreamingVideo(const string &playVideo) { screen->w, screen->h, screen->format->BitsPerPixel, + false, vlcPluginsPath, SystemFlags::VERBOSE_MODE_ENABLED); } @@ -4596,6 +4597,7 @@ void Game::playStreamingVideo(const string &playVideo) { screen->w, screen->h, screen->format->BitsPerPixel, + false, vlcPluginsPath, SystemFlags::VERBOSE_MODE_ENABLED); } diff --git a/source/glest_game/main/battle_end.cpp b/source/glest_game/main/battle_end.cpp index 3eaa50709..149dcf4c4 100644 --- a/source/glest_game/main/battle_end.cpp +++ b/source/glest_game/main/battle_end.cpp @@ -338,6 +338,7 @@ void BattleEnd::initBackgroundVideo() { screen->w, screen->h, screen->format->BitsPerPixel, + true, vlcPluginsPath, SystemFlags::VERBOSE_MODE_ENABLED); menuBackgroundVideo->initPlayer(); diff --git a/source/glest_game/main/intro.cpp b/source/glest_game/main/intro.cpp index 6f34f5cfd..6451b89ba 100644 --- a/source/glest_game/main/intro.cpp +++ b/source/glest_game/main/intro.cpp @@ -526,6 +526,7 @@ Intro::Intro(Program *program): screen->w, screen->h, screen->format->BitsPerPixel, + false, vlcPluginsPath, SystemFlags::VERBOSE_MODE_ENABLED); player.PlayVideo(); diff --git a/source/glest_game/menu/main_menu.cpp b/source/glest_game/menu/main_menu.cpp index 35a431e0f..61a47bf81 100644 --- a/source/glest_game/menu/main_menu.cpp +++ b/source/glest_game/menu/main_menu.cpp @@ -128,6 +128,7 @@ void MainMenu::initBackgroundVideo() { screen->w, screen->h, screen->format->BitsPerPixel, + true, vlcPluginsPath, SystemFlags::VERBOSE_MODE_ENABLED); menuBackgroundVideo->initPlayer(); diff --git a/source/glest_game/menu/menu_state_connected_game.cpp b/source/glest_game/menu/menu_state_connected_game.cpp index 68f67479b..9af440fff 100644 --- a/source/glest_game/menu/menu_state_connected_game.cpp +++ b/source/glest_game/menu/menu_state_connected_game.cpp @@ -3857,6 +3857,7 @@ void MenuStateConnectedGame::initFactionPreview(const GameSettings *gameSettings screen->w, screen->h, screen->format->BitsPerPixel, + true, vlcPluginsPath, SystemFlags::VERBOSE_MODE_ENABLED); factionVideo->initPlayer(); diff --git a/source/glest_game/menu/menu_state_custom_game.cpp b/source/glest_game/menu/menu_state_custom_game.cpp index 96e6720bd..b6f15991a 100644 --- a/source/glest_game/menu/menu_state_custom_game.cpp +++ b/source/glest_game/menu/menu_state_custom_game.cpp @@ -2744,6 +2744,7 @@ void MenuStateCustomGame::initFactionPreview(const GameSettings *gameSettings) { screen->w, screen->h, screen->format->BitsPerPixel, + true, vlcPluginsPath, SystemFlags::VERBOSE_MODE_ENABLED); factionVideo->initPlayer(); diff --git a/source/shared_lib/include/graphics/video_player.h b/source/shared_lib/include/graphics/video_player.h index 4110520d6..8799c0cc9 100644 --- a/source/shared_lib/include/graphics/video_player.h +++ b/source/shared_lib/include/graphics/video_player.h @@ -45,6 +45,7 @@ protected: bool stop; bool finished; + bool loop; VideoLoadingCallbackInterface *loadingCB; ctx *ctxPtr; @@ -61,7 +62,7 @@ public: string filenameFallback, SDL_Surface *surface, int x, int y, int width, int height, int colorBits, - string pluginsPath,bool verboseEnabled=false); + bool loop, string pluginsPath,bool verboseEnabled=false); virtual ~VideoPlayer(); static void setDisabled(bool value) { disabled = value; } diff --git a/source/shared_lib/sources/graphics/video_player.cpp b/source/shared_lib/sources/graphics/video_player.cpp index 48c338e4c..dd133a1e9 100644 --- a/source/shared_lib/sources/graphics/video_player.cpp +++ b/source/shared_lib/sources/graphics/video_player.cpp @@ -412,7 +412,9 @@ VideoPlayer::VideoPlayer(VideoLoadingCallbackInterface *loadingCB, string filenameFallback, SDL_Surface *surface, int x, int y,int width, int height,int colorBits, - string pluginsPath, bool verboseEnabled) : ctxPtr(NULL) { + bool loop, string pluginsPath, bool verboseEnabled) + : ctxPtr(NULL) { + this->loadingCB = loadingCB; this->filename = filename; this->filenameFallback = filenameFallback; @@ -422,6 +424,7 @@ VideoPlayer::VideoPlayer(VideoLoadingCallbackInterface *loadingCB, this->width = width; this->height = height; this->colorBits = colorBits; + this->loop = loop; this->pluginsPath = pluginsPath; //this->verboseEnabled = true; this->verboseEnabled = verboseEnabled; @@ -492,6 +495,11 @@ bool VideoPlayer::initPlayer(string mediaURL) { ctxPtr->vlc_argv.push_back("--no-video-title-show"); //ctxPtr->vlc_argv.push_back("--network-caching=10000"); + if(loop == true) { + ctxPtr->vlc_argv.push_back("--loop"); + ctxPtr->vlc_argv.push_back("--repeat"); + } + #if defined(LIBVLC_VERSION_PRE_2) ctxPtr->vlc_argv_str.push_back("--plugin-path=" + pluginsPath); ctxPtr->vlc_argv.push_back(ctxPtr->vlc_argv_str[ctxPtr->vlc_argv_str.size()-1].c_str()); @@ -659,6 +667,10 @@ bool VideoPlayer::initPlayer(string mediaURL) { /* Create a new item */ if(verboseEnabled) printf("In [%s] Line: %d, m [%p]\n",__FUNCTION__,__LINE__,ctxPtr->m); + if(loop == true) { + libvlc_media_add_option(ctxPtr->m, "input-repeat=-1"); + } + if(mediaURL.find(HTTP_PREFIX) == 0) { ctxPtr->mp = libvlc_media_player_new(ctxPtr->libvlc); } @@ -1401,6 +1413,21 @@ bool VideoPlayer::playFrame(bool swapBuffers) { } void VideoPlayer::RestartVideo() { + printf("Restart video\n"); + + this->stop = false; + this->finished = false; + ctxPtr->started = true; + ctxPtr->error = false; + ctxPtr->stopped = false; + ctxPtr->end_of_media = false; + ctxPtr->isPlaying = true; + ctxPtr->needToQuit = false; + + return; + + this->closePlayer(); + this->stop = false; this->finished = false; this->successLoadingLib = false;