New resource: GUIVideo for TX2D 3.0.0.0
by Jason Cahill · in Torque X 2D · 07/19/2009 (11:30 am) · 27 replies
Here's a piece of engine code I developed for myself that I thought I'd share with the community. It allows you to add WMV-based video to your TorqueX project, utilizing the awesome new support for video in XNA 3.1. Enjoy!
www.garagegames.com/community/resources/view/17871
www.garagegames.com/community/resources/view/17871
About the author
#22
11/17/2009 (3:50 pm)
I had to use Jacob's workaround with TX2D 3.1.4.0 to get it to work on the XBox. I also had to comment out the _material.Stop(); line in the VideoFilename property in GUIVideo.cs to solve another race condition._vid.VideoFilename = @"data\movies\splash"; _vid.Play();The _vid.Play() was getting executed before the _material.Stop() in the VideoFilename property. The end result is that the movie would stop and not play.
#23
I'm from the land of 3D and was wondering if any of you, got the video functionality to work? such as pause, stop, or resume?
The video sample which is based on this code from Jason, gives an error whenever I try to either pause, stop, or resume the video. I am using Torque X 3D though. But I did try Jasons code and with a tweak it ran.
Here's the post in the 3D forums I started. I'd really love some advice as I'm needing video for a project which is due in a week!;-)
www.torquepowered.com/community/forums/viewthread/111123/1#comment_form
Thanks for your time!
02/17/2010 (8:06 am)
Hey all,I'm from the land of 3D and was wondering if any of you, got the video functionality to work? such as pause, stop, or resume?
The video sample which is based on this code from Jason, gives an error whenever I try to either pause, stop, or resume the video. I am using Torque X 3D though. But I did try Jasons code and with a tweak it ran.
Here's the post in the 3D forums I started. I'd really love some advice as I'm needing video for a project which is due in a week!;-)
www.torquepowered.com/community/forums/viewthread/111123/1#comment_form
Thanks for your time!
#24
02/17/2010 (7:54 pm)
not sure if this would be useful to you: www.torquepowered.com/community/resources/view/18957
#25
Yeah I had a look at that before; it’s a really useful resource. I'm working in Torque X 3D though and I'm not sure how compatible it will be? I'm not a coder you see, I can do a little but I'm a designer primarily.
I suppose it theory the principle is the same I just need to change the 2D components to 3D. I see it uses Microsoft.Xna.Framework.Media and the player which comes with XNA 3.1, does all the functioanlity work?
02/18/2010 (8:16 am)
Hey Duncan,Yeah I had a look at that before; it’s a really useful resource. I'm working in Torque X 3D though and I'm not sure how compatible it will be? I'm not a coder you see, I can do a little but I'm a designer primarily.
I suppose it theory the principle is the same I just need to change the 2D components to 3D. I see it uses Microsoft.Xna.Framework.Media and the player which comes with XNA 3.1, does all the functioanlity work?
#26
All the functionality should work - I'm just using the video control that MS provided in XNA 3.1
02/18/2010 (11:23 am)
For working in TX3D you will probably find the VideoMaterial part of the resource most useful. Since it just renders the video to a material you should be able to then use that material like you would use any other material in TX3D.All the functionality should work - I'm just using the video control that MS provided in XNA 3.1
#27
Thanks again, I'll let you know how i get on!
02/18/2010 (12:13 pm)
Ah great! Thanks duncan, I'll give it a whirl. I thought it was what MS provided.Thanks again, I'll let you know how i get on!
Torque Owner Jacob Lynch
VideoMaterial.cs:
Add this with the rest of the using statements.
Then on what becomes line 103 right after _videoPlayer.play(_video); add:
while (_videoPlayer.PlayPosition == TimeSpan.Zero) Thread.Sleep(1);There seems to be some kind of race condition here, and I don't know enough about this stuff to fully explain it. It seems like the play member function takes a lot longer to load and start the video initially on Xbox than PC, and I'm guessing that either a subsequent call to stop or play (both of which occur) before the video is finished starting playing will cause it to not play on the Xbox.
From measurements I took, the test video I was using loaded in 5ms on the PC, and it took 46ms on the Xbox. Waiting for the video to finish loading or whatever is happening in the play function seems to allow it to work properly.
I haven't verified that sound remains perfectly synchronized, but since the video is stopped right after the function returns to GUIVideo, and then played again later, I'm not sure why it wouldn't be synchronized.
Hopefully someone who knows this better can explain what is happening or offer a better solution; this is just so I can continue working on other stuff.