Tutorial

Oct 11, 2007 at 8:43 AM
Hi,

I was searching the web for the solution to put video in xna. And i found this :)
To bad there is no documentation or something.

Can someone plz make a short tutorial on how to use in XNA?
Coordinator
Oct 13, 2007 at 2:17 PM
here's the rough steps, and yes, I will strive to post a sample app soon:
1. get the code from this project, and compile it
2. Add Scurvy.Media.Video.Pipeline to the project's content pipeline tab
3. Add a reference from your game, to Scurvy.Media.Video
4. Add your video to your XNA Game Studio Express project, it should default to the scurvy media importer and processor.
5. In your game, declare a new VideoContentManager, and load your video using that:
ContentManager content = new VideoContentManager(Services);
Video vid = content.Load<Video>("myVideo");
vid.Loop = true; //or false
vid.Play();

6. Call the video's update method in the game's update method:
vid.Update();

7. In the game's render method, render the video's current texture using whatever means you choose. This example will let you render it using a sprite batch:
if (vid.IsPlaying)
{
batch.Begin();
batch.Draw(vid.CurrentTexture, new Vector2(10, 10), Color.White);
batch.End();
}
Nov 25, 2007 at 1:56 PM
I can't seem to get a video to load. I downloaded the binary version v0.5.2007.1104. I then added Scruvy.Media.Video.Pipeline to the project's content pipeline tab along with adding a the reference. Step 4 is where I think my problem is because the code works up until trying to find the video. What do you mean is should defualt to importer and processor. Where do I put the video file at in the project. There is no fold importer and processor. This is awsome BTW I was wondering if you could play videos in XNA and I ran in to this site. Thanks.
Coordinator
Nov 25, 2007 at 3:05 PM
You can just add the .avi video to your project (right click, add new item). When it's added, you should be able to highlight the video in solution explorer, and look at the property grid (press f4 if it isn't already up). You will see that the importer and processor should be set to the right value ("Avi Video - Scurvy Media", and "Streaming Video - Scurvy Media").

Once you do that, the rest should work as the instructions above.

Let me know if you have any further issues :-)
Nov 25, 2007 at 4:35 PM
I get the following error:

Error 1 Building content threw Exception: Exception in VideoStreamGetFrameOpen!
at Scurvy.Media.Avi.AviVideoStream.GetFrameOpen() in C:\Dev\codeplex\ScurvyMedia\Scurvy.Video\Video.Content.Pipeline\Avi\AviVideoStream.cs:line 439
at Scurvy.Media.Pipeline.AviImporterBgr565.Initialize(String filename) in C:\Dev\codeplex\ScurvyMedia\Scurvy.Video\Video.Content.Pipeline\AviImporter.cs:line 36
at Scurvy.Media.Pipeline.VideoImporter`1.Import(String filename, ContentImporterContext context) in C:\Dev\codeplex\ScurvyMedia\Scurvy.Video\Video.Content.Pipeline\VideoImporter.cs:line 21
at Microsoft.Xna.Framework.Content.Pipeline.ContentImporter`1.Microsoft.Xna.Framework.Content.Pipeline.IContentImporter.Import(String filename, ContentImporterContext context)
at Microsoft.Xna.Framework.Content.Pipeline.BuildCoordinator.ImportAssetDirectly(BuildItem item, String importerName)
at Microsoft.Xna.Framework.Content.Pipeline.BuildCoordinator.ImportAsset(BuildItem item)
at Microsoft.Xna.Framework.Content.Pipeline.BuildCoordinator.BuildAssetWorker(BuildItem item)
at Microsoft.Xna.Framework.Content.Pipeline.BuildCoordinator.BuildAsset(BuildItem item)
at Microsoft.Xna.Framework.Content.Pipeline.BuildCoordinator.RunTheBuild()
at Microsoft.Xna.Framework.Content.Pipeline.Tasks.BuildContent.RemoteProxy.RunTheBuild(BuildCoordinatorSettings settings, TimestampCache timestampCache, ITaskItem[] sourceAssets, String[]& outputContent, String[]& rebuiltContent, String[]& intermediates, Dictionary`2& dependencyTimestamps, KeyValuePair`2[]& warnings) C:\Users\*****\Documents\Visual Studio 2005\Projects\Blaster\Blaster\Game\Bear.avi Game

The Bear.avi file is just a small clip that I found on vista and converted to .avi. Thanks for your help!
Coordinator
Nov 26, 2007 at 1:06 PM
thus far, any initialization errors I've seen have been related to codec issues. Try installing the cccp (combined community codec pack -- http://www.cccp-project.net/) and see if it still gives you problems.
Oct 31, 2008 at 12:50 PM
Edited Oct 31, 2008 at 1:05 PM
Hello, I've got a similar error with the latest version of Scurvy Media (0525)

Error    1    Building content threw Exception: Exception in VideoStreamGetFrameOpen!
   at Scurvy.Media.Avi.AviVideoStream.GetFrameOpen() in C:\Dev\codeplex\ScurvyMedia\Scurvy.Media\Scurvy.Media.Pipeline\Video\Avi\AviVideoStream.cs:line 439
   at Scurvy.Media.Pipeline.Video.Avi.AviVideoContent.<get_Frames>d__0.MoveNext() in C:\Dev\codeplex\ScurvyMedia\Scurvy.Media\Scurvy.Media.Pipeline\Video\Avi\AviVideoContent.cs:line 44
   at Scurvy.Media.Pipeline.Video.VidContentWriter`1.Write(ContentWriter output, T value) in C:\Dev\codeplex\ScurvyMedia\Scurvy.Media\Scurvy.Media.Pipeline\Video\VidContentWriter.cs:line 22
   at Microsoft.Xna.Framework.Content.Pipeline.Serialization.Compiler.ContentTypeWriter`1.Write(ContentWriter output, Object value)
   at Microsoft.Xna.Framework.Content.Pipeline.Serialization.Compiler.ContentWriter.InvokeWriter[T](T value, ContentTypeWriter writer)
   at Microsoft.Xna.Framework.Content.Pipeline.Serialization.Compiler.ContentWriter.WriteObject[T](T value)
   at Microsoft.Xna.Framework.Content.Pipeline.Serialization.Compiler.ContentCompiler.Compile(Stream output, Object value, TargetPlatform targetPlatform, String rootDirectory, String referenceRelocationPath)
   at Microsoft.Xna.Framework.Content.Pipeline.BuildCoordinator.SerializeOutputAsset(BuildItem item, Object assetData, String outputFilename)
   at Microsoft.Xna.Framework.Content.Pipeline.BuildCoordinator.SerializeAsset(BuildItem item, Object assetData)
   at Microsoft.Xna.Framework.Content.Pipeline.BuildCoordinator.BuildAssetWorker(BuildItem item)
   at Microsoft.Xna.Framework.Content.Pipeline.BuildCoordinator.BuildAsset(BuildItem item)
   at Microsoft.Xna.Framework.Content.Pipeline.BuildCoordinator.RunTheBuild()
   at Microsoft.Xna.Framework.Content.Pipeline.Tasks.BuildContent.RemoteProxy.RunTheBuild(BuildCoordinatorSettings settings, TimestampCache timestampCache, ITaskItem[] sourceAssets, String[]& outputContent, String[]& rebuiltContent, String[]& intermediates, Dictionary`2& dependencyTimestamps, KeyValuePair`2[]& warnings)    C:\*****\Eigene Dateien\Visual Studio 2005\Projects\VideoSupport\VideoSupport\Content\TestVideo.avi    VideoSupport


Does the cccp help here too? Thanks for your help!




Oct 31, 2008 at 1:07 PM
And this is my code:

namespace VideoSupport
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;
        ContentManager vContent;
        Video vid;

        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
        }

        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            vContent = new VideoContentManager(Services);
            vid.Loop = true;
            vid.Play();

            base.Initialize();
        }

        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            vid = vContent.Load<Video>("TestVideo");
            

            // TODO: use this.Content to load your game content here
        }

        /// <summary>
        /// UnloadContent will be called once per game and is the place to unload
        /// all content.
        /// </summary>
        protected override void UnloadContent()
        {
            // TODO: Unload any non ContentManager content here
        }

        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            KeyboardState kbState = Keyboard.GetState();
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();
            if (kbState.IsKeyDown(Keys.Escape))
            {
                this.Exit();
            }

            // TODO: Add your update logic here

            vid.Update();

            base.Update(gameTime);
        }

        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            graphics.GraphicsDevice.Clear(Color.CornflowerBlue);

            // TODO: Add your drawing code here

            if (vid.IsPlaying)
            {
                spriteBatch.Begin();
                spriteBatch.Draw(vid.CurrentTexture, new Vector2(10, 10), Color.White);
                spriteBatch.End();
            }

            base.Draw(gameTime);
        }
    }
}
Oct 31, 2008 at 1:29 PM
I have installed the cccp now and run the debug mode.

Yet I've got another error: "System.OutOfMemoryException"
Is it possible that my video is too large (39 sec, 3.9 MB)? I'll try to cut it into pieces of 5-10 seconds. I hope it'll work then.