View Single Post
Old 09-17-2009, 11:08 AM
therealtomlapp therealtomlapp is offline
Join Date: Jan 2009
Location: New Jersey
Posts: 40
Default Null Reference Exception error when playing DirectX video

I am creating a program for my theater pc that when I play a movie will play a few trailers before it using DirectX. Basically the video panel i've created is a custom control for me to finally insert into the program itself. When you use the control you can optionally insert a few trailers into a collection, then fire the code to play the movie. It will play all the trailers until the collection is exhausted, then play the movie. It plays the first trailer just fine, then when it goes to play the second one I get a generic "Null Reference Exception" error that does not point to any particular line of code. I ended up putting in an event to literally output messages telling me what line of code is about to be executed beforehand so I could get a better idea of when the error is happening.

Here are the steps to recreate the error:

1. From my test program, I execute the following

With VideoPanel1
.InjectMovieTrailer("E:\Media Folders\Intro Trailers\DOLBY DIGITAL\Canyon.AVI")
.InjectMovieTrailer("E:\Media Folders\Intro Trailers\THX\VTS_17_1.AVI")
End With

VideoPanel1.PlayVideoWithTrailers("e:\Media Folders\Movies\8mm.avi", 1)

2. The first trailer (Canyon.avi) begins to play, then it ends, my code executes the VideoPlayer.dispose() function to clear resources, which is also needed so the video codecs unload.

3. Then it waits 5 seconds, which gives the system enough time to unload all the codecs. This is needed since I have my computer connected via spdif to a Dolby Digital surround system, without the delay the next video ends up playing without sound.

4. Then PlayNextTrailer() is executed, which takes it back to get the next trailer from the list and set up the playback

5. I put code in my test program to output all my custom debug messages into a listbox so I can see what is about to happen before the error occurs.

6. As I watch the list, I see that the error happens after the next VideoPlayer.Play() function is executed, then I get the generic error.

The funny thing is when the error occurs, you can still see that the next trailer is playing, but obviously I still need to stop the crash from happening. I've experimented with different video files, just to be sure I wasn't using a partially corrupt video file. No matter what it always crashes on the second play, and my try/catch block does me no good.

I am fairly new to DirectX, but am well seasoned in vb coding. If anyone who knows more about DirectX has any ideas for me please let me know, I will greatly appreciate it.
Reply With Quote