0

i want to develop a video player which has to play different parts in a video (specified by their start n end positions). I am using directx.audiovideoplayback dll for this purpose. the starting and ending positions are stored in an array. eg- {2,6,8,19} tells that segment between 2nd to 6th second has to be played and then 8th to 19th second should be played.

my problem is that despite me giving condition that if(video_obj.CurrentPosition==endtime) video_obj.Stop(); the video isnt stopping.. the video is playing from 2nd position to end of file.

code is

 public static int[] seconds = { 3,8,12,16};
    public static int start, end;
    private void btnPlay_Click(object sender, EventArgs e)
    {
        vdo.Owner = panel1;
        panel1.Width = 300;
        panel1.Height = 150;
        vdoTrackBar.Minimum = 0;
        vdoTrackBar.Maximum = Convert.ToInt32(vdo.Duration);

        if (vdo != null)
        {
            vdo.Play();
            timer1.Start();
        }
    }
private void vdoTrackBar_Scroll(object sender, EventArgs e)
    {
        if (vdo != null)
        {
            vdo.CurrentPosition = vdoTrackBar.Value;
        }
    }

    private void timer1_Tick(object sender, EventArgs e)
    {
        int i;
        for (i = 0; i < seconds.Length; i = i + 2)
        {
            start = seconds[i];
            vdo.CurrentPosition = start;
            end = seconds[i + 1];
            vdoTrackBar.Value = (int)vdo.CurrentPosition;

            MessageBox.Show("Starts at " + vdo.CurrentPosition + " and Ends at " + end);
            if (vdo.Paused)
                vdo.Play();
            if (vdo.Playing)
            {
                if (vdo.CurrentPosition == vdo.Duration)
                {
                    timer1.Stop();
                    vdo.Pause();
                    vdoTrackBar.Value = 0;
                }
                if (vdo.CurrentPosition == end)
                {
                    timer1.Stop();
                    vdo.Pause();
                }

                vdoTrackBar.Value += 1;
            }
        }  

Help! Somewhere something is wrong and i have no clue about it How do i correct it? Video starts playing when i

user1188979
  • 1
  • 1
  • 3
  • Can you show more code? Some of the code you mention in your post doesn't match the given code block. I can see what look to be issues but I can't really be sure. An example would be your for loop. It looks like your are starting the same timer for each interation of the loop? Is that intended? timertick references another global timer (timer1 vs timer)? Basically, we need more info. – Kenneth Ito Jun 13 '12 at 00:57
  • edited the code! :) Help please! – user1188979 Jun 13 '12 at 05:58

1 Answers1

0

So there still isn't enough info in the post to really definitively say whats going wrong. I'm guessing that your timer isn't ticking with enough resolution to happen to tick exactly when the for loop in the timer tick would coincide with the video's current position.

How often does the timer tick? What's the precision of the video's current position?

Kenneth Ito
  • 5,201
  • 2
  • 25
  • 44
  • timer tick interval is 1000 and video current position will be an integer value. Even my intuition said that there might be some timer-tick-resolution-problem but i dont know how to figure it out – user1188979 Jun 13 '12 at 09:00