Sign in to follow this  

[.net] Looping/Switching Video Crashes - Managed DirectX

This topic is 3308 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello all, I'm really at a loss here. I can not seem to get my video app to loop a video. I'm using AudioVideoPlayback and followed the many tutorials out there in getting the basics setup. I can easily switch videos when it's tied to a keypress, but if I want a video to automatically start over or jump to a new one when finished playing ("Ending" event) then Application.Run() throws a null exception. I have tried: - double buffering the loading/unloading of my video files to give the old one enough time to dispose. - forced garbage collection with waiting until it's done - catching dispose even and waiting until it's done (infinite loop) Goal: - I just want to have a few movies (predefined) that I can cycle through with key presses and if a key isn't pressed they are played in sequence. This is my video create/destroy code:
// kill the current, which should be 2
if (m_video_2 != null)
{
m_video_2.Stop();
m_video_2.Dispose();
GC.Collect();
GC.WaitForPendingFinalizers();
m_video_2 = null;
}

// create new video in 1
m_video_1 = new Video(filename);
m_video_1.Owner = this;
m_video_1.Size = this.Size;
m_video_1.Ending += new EventHandler(video_Ending);
m_video_1.Play();
m_use_first = false;
The app crashes at Run() below but only when trying to play/switch in "Ending" event for the video:
static void Main()
{
Application.EnableVisualstyles();
Application.SetCompatibleTextRenderingDefault(false);
VideoPanel vp = new VideoPanel();
Application.Run(vp);
}
For completeness, here's my "Ending" event handler:
private void video_Ending(object sender, EventArgs e)
{
	// go to next video in sequence
	if (m_current_video == (m_num_videos - 1))
	{ m_current_video = 0; video_PlayMovie(m_filenames[0]); return; }

	m_current_video += 1;
	video_PlayMovie(m_filenames[m_current_video]);
	return;
}
Any ideas? Any help would really be appreciated. Thanks Eric

Share this post


Link to post
Share on other sites
Perhaps the callback is on another thread? You could try a BeginInvoke() so it runs on the form's thread?

Personally I would recommend you use DirectShowNet instead as AudioVideoPlayback is a very limited (and buggy) and is essentially a wrapper for DirectShow anyway.

Share this post


Link to post
Share on other sites

This topic is 3308 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this