How to trigger actions after a Theora video is finished?
by David Murray · in Torque Game Engine · 03/15/2006 (9:18 am) · 11 replies
Hey,
Does anybody know how to get Torque to realise when a Theora video is finished playing and trigger an action accordingly? I'll explain. I have a game area with several video triggers.When the user collides with a trigger a Theora video is triggered which plays full screen. The TheoraCtrl is part of the PlayGui so the TheoraCtrl plays over what the user sees in the game world. (hope that makes sense).
I need to Torque to know when a video is triggered and finished so that I can turn the sound from the game level off while the video is playing. Basically, it would be while theora is playing, all other sounds volume = 0, when the video finishes all other sounds volume = 1. Not sure how to go about it though, anyone any ideas?
Does anybody know how to get Torque to realise when a Theora video is finished playing and trigger an action accordingly? I'll explain. I have a game area with several video triggers.When the user collides with a trigger a Theora video is triggered which plays full screen. The TheoraCtrl is part of the PlayGui so the TheoraCtrl plays over what the user sees in the game world. (hope that makes sense).
I need to Torque to know when a video is triggered and finished so that I can turn the sound from the game level off while the video is playing. Basically, it would be while theora is playing, all other sounds volume = 0, when the video finishes all other sounds volume = 1. Not sure how to go about it though, anyone any ideas?
About the author
#2
trigger entered 2 times, video still playing (even though the video has stopped)
trigger entered 3 times, video still playing (and so on)
I've tried using this part
if ( $timesEntered >= 2 && videoDialog.done == true ) {
echo( "","trigger entered " @ $TimesEnteredTotal @" times & video has finished" );
videoDialog.setVisible(false);
}
in the onLeaveTrigger and onTickTrigger but still no luck. It seems that it doesnt know that the video is finished, but it must if it makes the TheoraCtrl invisible when it finishes.
03/16/2006 (4:49 am)
Thanks for the help Tim, code works fine, except for the part that realises when the video is finished. When the video stops my TheoraCtrl which is called Theo returns to being invisible but the console still says that the video is playing. When the video finishes and I return to the game area I get this in the console when I enter the trigger again:trigger entered 2 times, video still playing (even though the video has stopped)
trigger entered 3 times, video still playing (and so on)
I've tried using this part
if ( $timesEntered >= 2 && videoDialog.done == true ) {
echo( "","trigger entered " @ $TimesEnteredTotal @" times & video has finished" );
videoDialog.setVisible(false);
}
in the onLeaveTrigger and onTickTrigger but still no luck. It seems that it doesnt know that the video is finished, but it must if it makes the TheoraCtrl invisible when it finishes.
#3
03/16/2006 (4:52 am)
Strange, I tested this & it worked fine for me.
#4
trigger entered 2 times, video still playing (even though the video has stopped)
trigger entered 3 times, video still playing (and so on)
I've tried using this part
if ( $timesEntered >= 2 && videoDialog.done == true ) {
echo( "","trigger entered " @ $TimesEnteredTotal @" times & video has finished" );
videoDialog.setVisible(false);
}
in the onLeaveTrigger and onTickTrigger but still no luck. It seems that it doesnt know that the video is finished, but it must if it makes the TheoraCtrl invisible when it finishes.
03/16/2006 (4:57 am)
Thanks for the help Tim, code works fine, except for the part that realises when the video is finished. When the video stops my TheoraCtrl which is called Theo returns to being invisible but the console still says that the video is playing. When the video finishes and I return to the game area I get this in the console when I enter the trigger again:trigger entered 2 times, video still playing (even though the video has stopped)
trigger entered 3 times, video still playing (and so on)
I've tried using this part
if ( $timesEntered >= 2 && videoDialog.done == true ) {
echo( "","trigger entered " @ $TimesEnteredTotal @" times & video has finished" );
videoDialog.setVisible(false);
}
in the onLeaveTrigger and onTickTrigger but still no luck. It seems that it doesnt know that the video is finished, but it must if it makes the TheoraCtrl invisible when it finishes.
#5
03/16/2006 (4:58 am)
Sorry 4 posting it twice,I'm still messing about with it.I'l let you know of any changes.
#6
That should read if ( $timesEntered >= 2 && whateverYouCalledYourVideoGui.done == true ) {
I can't see how this isn't working for you? I've tested it 25 times now & it works fine???
The video is automatically made invisible when it's finished by default. The schedule to check if its done just checks the 'done' flag in the theroa gui which is set to true once its finished playing. I assure you this function works, as long as ALL references to videoDialog are changed to your video gui name in the script I gave you
03/16/2006 (7:22 am)
This might seem stupid but just checking,Quote:
I've tried using this part
if ( $timesEntered >= 2 && videoDialog.done == true ) {
echo( "","trigger entered " @ $TimesEnteredTotal @" times & video has finished" );
videoDialog.setVisible(false);
}
That should read if ( $timesEntered >= 2 && whateverYouCalledYourVideoGui.done == true ) {
I can't see how this isn't working for you? I've tested it 25 times now & it works fine???
The video is automatically made invisible when it's finished by default. The schedule to check if its done just checks the 'done' flag in the theroa gui which is set to true once its finished playing. I assure you this function works, as long as ALL references to videoDialog are changed to your video gui name in the script I gave you
#7
This is my theora gui which is in playGui.cs
You must make sure that EVERY instance of videoDialog is changed in videoTrigger.cs to match the name of your GuiTheoraCtrl
03/16/2006 (7:30 am)
Not trying to sound rude or insulting but you must be doing something wrong.This is my theora gui which is in playGui.cs
new GuiTheoraCtrl(videoDialog) { [b]//note the name, videoDialog[/b]
Profile = "GuiDefaultProfile";
HorizSizing = "right";
VertSizing = "bottom";
position = "0 0";
Extent = "64 64";
MinExtent = "8 2";
Visible = "0";
done = "0"; [b]//here's the done flag[/b]
stopOnSleep = "0";
backgroundColor = "0 0 0 255";
};You must make sure that EVERY instance of videoDialog is changed in videoTrigger.cs to match the name of your GuiTheoraCtrl
#8
if ( $timesEntered >= 2 && Theo.done == true ) {
echo( "","trigger entered " @ $TimesEnteredTotal @" times & video has finished" );
Theo.setVisible(false);
which pretty much resets everything. Thanks for the help Tim
03/16/2006 (7:55 am)
K, finally gt it working.Weird, I just put $TimesEntered=0; afterif ( $timesEntered >= 2 && Theo.done == true ) {
echo( "","trigger entered " @ $TimesEnteredTotal @" times & video has finished" );
Theo.setVisible(false);
which pretty much resets everything. Thanks for the help Tim
#9
04/21/2009 (11:23 am)
Espero poder usrlo y me sirva, gracias por la explicacion
#10
Please let me know if I need to post my code to make it easier, thanks
12/17/2009 (5:23 pm)
I have a small problem...the trigger does not play the video but does play the sound from the video....anybody has any ideas what I might have done wrong? ThanksPlease let me know if I need to post my code to make it easier, thanks
#11
parameter is an incorrect parameter. It always evaluates to true, even when the video is in the middle or just started.
02/06/2010 (4:24 pm)
thatvideoDialog.done
parameter is an incorrect parameter. It always evaluates to true, even when the video is in the middle or just started.
Torque Owner Tim Heldna
1) Create your theora video gui component, when you save it set it to not be visible. Name it whatever you want. In the example script below mine is called videoDialog, change the script to suit whatever you called yours.
2) Create a file called videoTrigger.cs, execute it in the usual manner from game.cs. Here's what to put in it...
$TimesEntered=0; $TimesEnteredTotal=0; // Schedule checking for if the video is done schedule(100, 0, checkVideoDialogDone); // Is the videoDialog video done? function checkVideoDialogDone() { // Video is done if (videoDialog.done) { videoDialog.setVisible(false); // Delete the profile //videoDialog.delete(); schedule(100, 0, checkVideoDialogDone); } // Not done yet so check again later else { schedule(100, 0, checkVideoDialogDone); } } datablock TriggerData(videoTrigger) { // The period is value is used to control how often the console // onTriggerTick callback is called while there are any objects // in the trigger. The default value is 100 MS. tickPeriodMS = 100; }; function videoTrigger::onEnterTrigger(%this,%trigger,%obj) { Parent::onEnterTrigger(%this,%trigger,%obj); $TimesEntered++; $TimesEnteredTotal++; if ( $timesEntered == 1 ) { echo( "","trigger entered, playing video" ); alxStopAll(); videoDialog.setVisible(true); videoDialog.setFile("starter.fps/client/ui/myVideo.ogg"); } if ( $timesEntered >= 2 && videoDialog.done == false ) { echo( "","trigger entered " @ $TimesEnteredTotal @" times, video still playing" ); $TimesEntered--; } if ( $timesEntered >= 2 && videoDialog.done == true ) { echo( "","trigger entered " @ $TimesEnteredTotal @" times & video has finished" ); videoDialog.setVisible(false); } } function videoTrigger::onLeaveTrigger(%this,%trigger,%obj) { Parent::onLeaveTrigger(%this,%trigger,%obj); echo( "","player left trigger" ); } function videoTrigger::onTickTrigger(%this,%trigger) { // This method is called every tickPerioMS, as long as any // objects intersect the trigger. The default onTriggerTick // method (in the C++ code) invokes the ::onTriggerTick(%trigger) method on // every object (whatever it's type) in the same group as the trigger. // You can iterate through the objects in the list by using these // methods: // %this.getNumObjects(); // %this.getObject(n); Parent::onTickTrigger(%this,%trigger); }3) Drop the trigger into the mission editor, save and that should do it.
As far as sound goes you may want to use commands like alxStop($simHandle); and so on. I used alxStopAll(); as I have no idea how sound is setup in your game. Depending on how you stop your sound, you may have to enable it again. This can be achieved quite easily as I have shown you how to check when the video is done.
Good luck, let me know if this helps.