"Cannot access a closed file" error message

Oct 25, 2007 at 8:09 PM
I've followed the instructions to play "ruby.avi" and it generated the above message after a couple of frames. If I comment out the call to vid.Update(), it stays static but it doesn't crashes.

Here's the stack trace:

System.ObjectDisposedException was unhandled
Message="Cannot access a closed file."
Source="mscorlib"
ObjectName=""
StackTrace:
at System.IO.__Error.FileNotOpen()
at System.IO.FileStream.Read(Byte[] array, Int32 offset, Int32 count)
at System.IO.BinaryReader.FillBuffer(Int32 numBytes)
at System.IO.BinaryReader.ReadInt32()
at Scurvy.Media.VideoStream.LoadNextFrame() in F:\my_doc\XnaStuff\Scurvy.Video\Video.Content\VideoStream.cs:line 67
at Scurvy.Media.VideoStream.getCurrentTexture() in F:\mydoc\XnaStuff\Scurvy.Video\Video.Content\VideoStream.cs:line 58
at WindowsGame1.Game1.Draw(GameTime gameTime) in F:\my_doc\XnaStuff\Scurvy.Video\WindowsGame1\Game1.cs:line 124
at Microsoft.Xna.Framework.Game.DrawFrame()
at Microsoft.Xna.Framework.Game.Tick()
at Microsoft.Xna.Framework.Game.HostIdle(Object sender, EventArgs e)
at Microsoft.Xna.Framework.GameHost.OnIdle()
at Microsoft.Xna.Framework.WindowsGameHost.ApplicationIdle(Object sender, EventArgs e)
at System.Windows.Forms.Application.ThreadContext.System.Windows.Forms.UnsafeNativeMethods.IMsoComponent.FDoIdle(Int32 grfidlef)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at Microsoft.Xna.Framework.WindowsGameHost.Run()
at Microsoft.Xna.Framework.Game.Run()
at WindowsGame1.Program.Main(String[] args) in F:\my_doc\XnaStuff\Scurvy.Video\WindowsGame1\Program.cs:line 14
Coordinator
Nov 1, 2007 at 2:20 PM
Are you using a VideoContentManager to load the video? if you're using a regular ContentManager, it will close the file stream before returning the Video object.
Nov 1, 2007 at 3:58 PM
That was the problem. I thought I had followed the instructions ;-|