Looping a Theora Video
by Neil Marshall · in Torque Game Engine · 11/18/2005 (7:52 am) · 36 replies
How would I go about looping a theora video?
or avi I guess. I just want my menu system to be non-static.
or avi I guess. I just want my menu system to be non-static.
#2
11/22/2005 (12:58 pm)
It doesn't look like it does it by default so I brute forced it. It's not perfect but it's simple to add.Left base folder: C:\Projects\tge14\torque
Right base folder: C:\Projects\tge14\TGE14Yecho
*** engine\gui\shiny\guiTheoraCtrl.cc 2005-09-09 11:13:01.000000000 -0500
--- engine\gui\shiny\guiTheoraCtrl.cc 2005-11-22 15:48:32.000000000 -0500
***************
*** 14,25 ****
--- 14,26 ----
IMPLEMENT_CONOBJECT(GuiTheoraCtrl);
GuiTheoraCtrl::GuiTheoraCtrl()
{
mFilename = StringTable->insert("");
mDone = false;
+ mLoop = true;
mStopOnSleep = false;
mBackgroundColor.set(0,0,0);
}
//----------------------------------------------------------------------------
GuiTheoraCtrl::~GuiTheoraCtrl()
***************
*** 32,43 ****
--- 33,45 ----
addGroup("Playback");
addField("theoraFile", TypeFilename, Offset(mFilename, GuiTheoraCtrl));
addField("done", TypeBool, Offset(mDone, GuiTheoraCtrl));
addField("stopOnSleep", TypeBool, Offset(mStopOnSleep, GuiTheoraCtrl));
+ addField("loop", TypeBool, Offset(mLoop, GuiTheoraCtrl));
addField("backgroundColor", TypeColorI,Offset(mBackgroundColor, GuiTheoraCtrl));
endGroup("Playback");
}
ConsoleMethod( GuiTheoraCtrl, setFile, void, 3, 3, "(string filename) Set an Ogg Theora file to play.")
***************
*** 100,113 ****
mTheoraTexture.refresh();
dglClearBitmapModulation();
dglDrawBitmapStretch(mTheoraTexture, rect);
}
else
{
! if(mTheoraTexture.isReady())
mDone = true;
dglDrawRectFill(rect, mBackgroundColor); // black rect
}
renderChildControls(offset, updateRect);
}
--- 102,119 ----
mTheoraTexture.refresh();
dglClearBitmapModulation();
dglDrawBitmapStretch(mTheoraTexture, rect);
}
else
{
! if(mTheoraTexture.isReady()) {
mDone = true;
+ if (mLoop) {
+ setFile(mFilename); // Play the animation again.
+ }
+ }
dglDrawRectFill(rect, mBackgroundColor); // black rect
}
renderChildControls(offset, updateRect);
}
*** engine\gui\shiny\guiTheoraCtrl.h 2005-09-09 11:13:01.000000000 -0500
--- engine\gui\shiny\guiTheoraCtrl.h 2005-11-22 15:49:18.000000000 -0500
***************
*** 34,45 ****
--- 34,46 ----
/// If true, stop video playback when the control goes to sleep.
bool mStopOnSleep;
/// Are we done with playback?
bool mDone;
+ bool mLoop;
/// Our background color.
ColorI mBackgroundColor;
bool onWake();
void onSleep();
#3
Here's something I found out the hard way: if you want to loop a video you started via setfile that isn't the one set in theoraFile, you need to make a minor adjustment in guiTheoraCtrl.cc:
Add the above line, or mFilename will not be updated to be the latest filename, and the wrong (or none) video file will loop.
03/13/2006 (10:36 pm)
Thanks for the code, Neil;Here's something I found out the hard way: if you want to loop a video you started via setfile that isn't the one set in theoraFile, you need to make a minor adjustment in guiTheoraCtrl.cc:
void GuiTheoraCtrl::setFile(const char* szFilename)
{
mDone = false;
+ mFilename = StringTable->insert(szFilename);
if(szFilename && szFilename[0])
mTheoraTexture.setFile(szFilename, true);
}Add the above line, or mFilename will not be updated to be the latest filename, and the wrong (or none) video file will loop.
#4
ConsoleMethod( GuiTheoraCtrl, setFile, void, 3, 3, "(string filename) Set an Ogg Theora file to play."){
object->setFile(argv[2]);
}
not sure how to modify it to get looping.. please help
thanks
03/23/2006 (2:55 pm)
My guiTheoraCtrl.cc looks different though:ConsoleMethod( GuiTheoraCtrl, setFile, void, 3, 3, "(string filename) Set an Ogg Theora file to play."){
object->setFile(argv[2]);
}
not sure how to modify it to get looping.. please help
thanks
#5
***************
*** 100,113 ****
in the code anywhere. Thats just for an autopatch utility to use.
03/24/2006 (12:21 pm)
You add the lines that have + signs and delete the lines that have - signs in the above posts. You won't see ***************
*** 100,113 ****
in the code anywhere. Thats just for an autopatch utility to use.
#6
Where do I have this piece?
+ if (mLoop) {
+ setFile(mFilename); // Play the animation again.
+ }
+ }
I tried adding it in onRender, but that didn't work.
here is the code I have:
03/27/2006 (11:28 am)
@Neil: thanks but that still doesn't make much sense, when compare the above code with the code I have. Where do I have this piece?
+ if (mLoop) {
+ setFile(mFilename); // Play the animation again.
+ }
+ }
I tried adding it in onRender, but that didn't work.
here is the code I have:
//-----------------------------------------------------------------------------
// Torque Game Engine
// Copyright (C) GarageGames.com, Inc.
//-----------------------------------------------------------------------------
#include "gui/core/guiControl.h"
#include "gui/shiny/guiTheoraCtrl.h"
#include "console/consoleTypes.h"
#include "dgl/dgl.h"
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
IMPLEMENT_CONOBJECT(GuiTheoraCtrl);
GuiTheoraCtrl::GuiTheoraCtrl()
{
mFilename = StringTable->insert("");
mDone = false;
mLoop =true;
mStopOnSleep = false;
mBackgroundColor.set(0,0,0);
}
//----------------------------------------------------------------------------
GuiTheoraCtrl::~GuiTheoraCtrl()
{
}
void GuiTheoraCtrl::initPersistFields()
{
Parent::initPersistFields();
addGroup("Playback");
addField("theoraFile", TypeFilename, Offset(mFilename, GuiTheoraCtrl));
addField("done", TypeBool, Offset(mDone, GuiTheoraCtrl));
addField("stopOnSleep", TypeBool, Offset(mStopOnSleep, GuiTheoraCtrl));
addField("loop", TypeBool, Offset(mLoop, GuiTheoraCtrl));
addField("backgroundColor", TypeColorI,Offset(mBackgroundColor, GuiTheoraCtrl));
endGroup("Playback");
}
ConsoleMethod( GuiTheoraCtrl, setFile, void, 3, 3, "(string filename) Set an Ogg Theora file to play.")
{
object->setFile(argv[2]);
}
ConsoleMethod( GuiTheoraCtrl, stop, void, 2, 2, "() Stop playback.")
{
object->stop();
}
ConsoleMethod( GuiTheoraCtrl, getCurrentTime, F32, 2, 2, "() Return the time elapsed in playback, in seconds.")
{
return object->getCurrentTime();
}
void GuiTheoraCtrl::setFile(const char* szFilename)
{
mDone = false;
mFilename = StringTable->insert(szFilename);
if(szFilename && szFilename[0])
mTheoraTexture.setFile(szFilename, true);
}
void GuiTheoraCtrl::stop()
{
mTheoraTexture.stop();
mDone = true;
}
//----------------------------------------------------------------------------
bool GuiTheoraCtrl::onWake()
{
if (!Parent::onWake()) return false;
if(mTheoraTexture.isReady())
return true;
setFile(mFilename);
return true;
}
//----------------------------------------------------------------------------
void GuiTheoraCtrl::onSleep()
{
Parent::onSleep();
if(mStopOnSleep)
stop();
}
//----------------------------------------------------------------------------
void GuiTheoraCtrl::onRender(Point2I offset, const RectI &updateRect)
{
const RectI rect(offset, mBounds.extent);
if(mTheoraTexture.isReady() && mTheoraTexture.isPlaying())
{
mTheoraTexture.refresh();
dglClearBitmapModulation();
dglDrawBitmapStretch(mTheoraTexture, rect);
}
else
{
if(mTheoraTexture.isReady()){
mDone = true;
}
dglDrawRectFill(rect, mBackgroundColor); // black rect
}
renderChildControls(offset, updateRect);
}
//----------------------------------------------------------------------------
void GuiTheoraCtrl::inspectPostApply()
{
stop();
setFile(mFilename);
}
#7
03/27/2006 (12:04 pm)
It goes in the onWake function. You'll need to add a { to the if statement. The ! on the line means that it's changed in some way... in this case it needed a {
#8
+ if (mLoop) {
+ setFile(mFilename); // Play the animation again.
+ }
+ }
in onrender is correct.
thanks
03/27/2006 (12:04 pm)
Ok nevermind, it does work. I dont' know why it didn't work the first time. so putting + if (mLoop) {
+ setFile(mFilename); // Play the animation again.
+ }
+ }
in onrender is correct.
thanks
#9
Sorry for the dumb artist questions here.
I too want a looping video. So in my guiTheoraCtrl.cc file, I add what?
Could someone post the code again ..gamer? .... ( my file also looks like the one gamer has posted ) as I'm not 100% where I have to post this stuff within my guiTheoraCtrl.cc file.
I assume I have to recompile Torque before it'll work then?
Cheers
harv
04/14/2006 (9:48 am)
GuysSorry for the dumb artist questions here.
I too want a looping video. So in my guiTheoraCtrl.cc file, I add what?
Could someone post the code again ..gamer? .... ( my file also looks like the one gamer has posted ) as I'm not 100% where I have to post this stuff within my guiTheoraCtrl.cc file.
I assume I have to recompile Torque before it'll work then?
Cheers
harv
#10
04/14/2006 (9:58 am)
Quote:Why? All the information you need is right here on this forum post. Open up your guiTheoraCtrl.cc file and compare it to Neil Marshall's original post. Just look for the '+' signs in Neils post, this indicates code that has been added. A '!' indicates where code has been changed.
Could someone post the code again ..gamer?
Quote:Yes.
I assume I have to recompile Torque before it'll work then?
#11
Thanks for your help.
8)
04/14/2006 (10:10 am)
Cheers Tim, I'll give it a go after the weekend....as I say, I'm not a coder, so any changes to .cc files make me a bit nervous is all. Thanks for your help.
8)
#12
I got this working a while ago, thanks for your help, I am now bugfixing my GUI.
Has anyone experiencing a very quick black/white flash as the video loops to the start again? If so how did you get rid of it?
Thanks for any advice you can give
harv
06/21/2006 (6:02 am)
Hi all.I got this working a while ago, thanks for your help, I am now bugfixing my GUI.
Has anyone experiencing a very quick black/white flash as the video loops to the start again? If so how did you get rid of it?
Thanks for any advice you can give
harv
#13
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=10468
06/21/2006 (6:24 am)
You may want to contact Tomwww.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=10468
#14
08/29/2006 (7:02 pm)
I'm using this code in my current project. Did anyone find an answer to the white flash when the video loops?
#15
the issue with looping and well the underlying TheoraTexture is more intense than once can first see. On the good side, we've (Doppelganger) have resolved majority of the issues with Theora (yes looping too) with some significant changes. I've been meaning to release a resource for a while now, but haven't found the time. Seems I better get on it again :)
08/30/2006 (3:03 pm)
Hi Guys,the issue with looping and well the underlying TheoraTexture is more intense than once can first see. On the good side, we've (Doppelganger) have resolved majority of the issues with Theora (yes looping too) with some significant changes. I've been meaning to release a resource for a while now, but haven't found the time. Seems I better get on it again :)
#16
The fix is just to make it render the last frame of the video instead of the filled rectangle, which should not be more taxing then rearranging a couple of lines of code.
08/30/2006 (9:08 pm)
If i remember rightly, the problem with the flashing on looping was just a really simple issue with the render method. When the theora video stopped, the gui control would render a filled rectangle instead of the actual texture.The fix is just to make it render the last frame of the video instead of the filled rectangle, which should not be more taxing then rearranging a couple of lines of code.
#17
09/18/2006 (8:00 am)
Sounds pretty easy....well....no actually? How do you add the last frame of the video file to fill that rectangle? Is this still done in the guiTheoraCtrl.cc file. I noticed that you can fill it with color, but not the actually frame to give it that flowing effect............ Any help would be greatly appreciated. Thx.
#18
10/13/2006 (4:12 pm)
I'm using the Theora player for an animated background in my main Gui, and i've managed to eliminate the white flash, but could someone please explain how to make the transition smoothly? Perhaps post the updated resource Lateral Punk was talking about? Thank you very much.
#19
10/17/2006 (6:28 am)
Hi, i thought itd be best for me to post on this thread... ive made my own start up trailer for my game, and it is in wmv format then i used guitheoractrl to load it but as soon as i click "Load" it exits the game. Any simular things? i think its because the format cant be wmv? i made my video in movie maker.
#20
10/17/2006 (6:41 am)
Saska: You'll need to convert your video to Theora format. Wikipedia has an excellent article if you search for Theora that includes a list of conversion software. I would recommend VLC. It's easy to use and produces decent results.
Torque Owner Aaron E
Default Studio Name