Reputation: 946
I want to show a video texture in my application with the video file being supplied by the user.
Texture2d
has a FromFile
method, but Video
doesn't.
Any ideas? (I only need PC support)
Thanks.
Upvotes: 5
Views: 5221
Reputation: 511
John U. You can open the XNB file with a hex editor and you'll see the format. The name of the corresponding video file is in there, you can overwrite it with the corresponding filename you need. That's what I've done for my project. Working on a way to write the binary file myself now.
Upvotes: 1
Reputation: 946
Well, it took me a while but I cracked this.
Going through the content pipeline is not an option, since you need GameStudio installed.
I ended up reverse engineering the XNA content builder to figure out how to make
my own XNB files. Turns out that for WMV files the XNB is a simple binary descriptor.
Now I just create an XNB for any WMVs I find in runtime, shove it into the Content folder,
and it works fine.
Upvotes: 0
Reputation: 201
As Aphid mentioned, you can modify the winform content loading sample.
To get it to accept WMVs, you need to modify like this:
Add VideoImporters to the assemblies array in ContentBuilder.cs:
static string[] pipelineAssemblies =
{
"Microsoft.Xna.Framework.Content.Pipeline.FBXImporter" + xnaVersion,
"Microsoft.Xna.Framework.Content.Pipeline.XImporter" + xnaVersion,
"Microsoft.Xna.Framework.Content.Pipeline.TextureImporter" + xnaVersion,
"Microsoft.Xna.Framework.Content.Pipeline.EffectImporter" + xnaVersion,
"Microsoft.Xna.Framework.Content.Pipeline.VideoImporters" + xnaVersion
};
Then in MainForm.cs change
contentBuilder.Add(fileName, "Model", null , "ModelProcessor");
to
contentBuilder.Add(fileName, "Video", "WmvImporter" , "VideoProcessor");
You will then have to play the video using the method described in the Playing a Video on a Surface example
This method only works error using the 3.1 version of the Content Loading example; in XNA 4 doing as i described throws a Pinvoke error. I have posted to the XNA forums in hopes of finding a solution to this problem.
EDIT: I received the following reply from an XNA Framework Dev in reference to the pinvoke exception:
You can safely ignore this warning. This MDA is turned on by default by VS2010 to indicate potential perf issues for pinvokes that don't have explicit calling convention declared. This used to be off by default before VS2010 so that's why you didn't see it in 3.1. We discovered this a little too late in the GS4 game to make it go away but essentially there're no issue with the functionality. You should only hit this when you're developing/debugging your custom processors. It is understandably annoying and you can turn it off by going into Debug->Exceptions->Managed Debugging Assistants->PInvokeStackImbalance. We will make this go away for the next release.
Upvotes: 2
Reputation: 364
You could try using the video API added in XNA 3.1, together with the winform content loading sample on the creators site. The sample shows how to allow the user to select a content file, and have the system compile it to .xnb and then load it back into memory at runtime.
Upvotes: 4
Reputation: 47759
You could also try the XNA DirectShow Video Player:
http://xnadsplayer.codeplex.com/
I've never used it, so not sure how well it works, but it's another option for you.
Upvotes: 0
Reputation: 47759
This unfortunately won't work ... their API requires that the video be processed through the content pipeline.
I haven't updated it since the video APIs were released by the XNA team, but you can check out this open source project I wrote, Scurvy.Media (http://scurvymedia.codeplex.com/). It was also a content pipeline, but perhaps you can modify it to work via a .FromFile type method.
feel free to contact me via codeplex if you have any questions. :-)
Upvotes: 1