Seamless video playlist

Jan 12, 2012 at 8:38 PM

Hi,

I am trying to create a simple video playlist UserControl. At the moment I only have 2 videos. I am constantly looking at the position of the current video and as soon as it is near the end, I play the second. Like so:

 

        void CompositionTarget_Rendering(object sender, EventArgs e)
        {
            if (CurrentPlayer == 1 && VideoPlayer1.IsPlaying)
            {
                long pos = VideoPlayer1.MediaPosition;
                long dur = VideoPlayer1.MediaDuration;

                if (dur - pos < 11000)
                {
                    CurrentPlayer = 2;
                    VideoPlayer2.Play();
                    VideoPlayer1.Visibility = System.Windows.Visibility.Hidden;
                    VideoPlayer2.Visibility = System.Windows.Visibility.Visible;
                }
            }
            else if (CurrentPlayer == 2 && VideoPlayer2.IsPlaying)
            {
                long pos = VideoPlayer2.MediaPosition;
                long dur = VideoPlayer2.MediaDuration;

                if (dur - pos < 11000)
                {
                    CurrentPlayer = 1;
                    VideoPlayer1.Play();
                    VideoPlayer2.Visibility = System.Windows.Visibility.Hidden;
                    VideoPlayer1.Visibility = System.Windows.Visibility.Visible;
                }
            }
        }

This works but there is still a small gap between playing videos. Does anyone know a better way of doing it?

Thanks.

Jan 16, 2012 at 2:16 PM
Edited Jan 16, 2012 at 2:16 PM

ofcourse there is gap between your movies,

you have two videorenderer types in wpfmediakit, VMR9 (directshow) and EVR(mediafoundation). VMR9 is much faster in allocation but still needs time to allocate himself and start playing video.

But, realize that WPF MediaKit works in separate thread and has own dispatcher. So, loading video don't interrupt any UI behaviors.

All you need to do is preload video for next movie when current movie is playing, like this

i don;t see you code when your are loading source so i can't tell you anything more,

consider implementing transition effect bettwen switching movies to hide gap