0

I hope someone will be able to help me with my issue. i want to take a screenshot of the video at a specific time index, however when i try to change the time all i get is a blank black screen. i added buttons which play and pause, it allows me to play and pause the video, if i do that and then change the time index, i get an image. im confused as to why it doesn’t work using code. i even preform btnplay.PeformClick(); to play the video and when i do btnpause.PerformClick() to pause the video it doesn’t.

it seems that i can only get an image of the video if i have to physically hit the play and then pause button on my form, im trying to achieve this using code

private void Form1_Load(object sender, EventArgs e)
        {
           


            ////////////////////LC4 VLC Settings///////////////////////////////////////////////////////////////////////////////////////////

            control = new VlcControl();
            var currentAssembly = Assembly.GetEntryAssembly();
            var currentDirectory = new FileInfo(currentAssembly.Location).DirectoryName;
            var libDirectory = new DirectoryInfo(Path.Combine(currentDirectory, "libvlc", IntPtr.Size == 4 ? "win-x86" : "win-x64"));
            control.BeginInit();
            control.VlcLibDirectory = libDirectory;
            control.Dock = DockStyle.Fill;
            control.EndInit();
            panel1.Controls.Add(control);
            
            main_form_LC4_data();
        }
        
         void main_form_LC4_data()
        {
        long vOut3 = 20;
        playfile("path to file");
        First_Frame(vOut3);
        }
        
          void playfile(string final)
        {
           control.SetMedia(new Uri(final).AbsoluteUri);
            control.Time = 0;
            control.Update();
            
        }
        
         void First_Frame(long vOut3)
        {
            control.Time = vOut3;

        }
        
          private void button9_Click(object sender, EventArgs e)
        {
            control.Play();
            Console.WriteLine("PLAY");
        }

        private void button8_Click(object sender, EventArgs e)
        {
           
            control.Pause();
            Console.WriteLine("PAUSE");
        }

Above is my code in a nut shell

i have tried things like this

private void button10_Click(object sender, EventArgs e)
        {
           First_Frame(first_frame); // jump to index
        }

and then calling up button10.PerformClick(); however it doesnt seem to work. once again if i physically hit the buttons on my form it works perfectly, however not in the way of coding it.

as an example :

  1. play.PeformClick();
  2. Pause.PeformClick();
  3. time = vOut3;

I do hope this isnt to confusing im really stuck and am still hoping someone can help me

Thank you

Vijay Yadav
  • 91
  • 13

1 Answers1

0

A few things:

control.Update();

this does nothing.

You need to wait for the Playing event to be raised after setting the time, otherwise libvlc doesn't have the time to decode the frame and display it (setting the time is asynchronous)

cube45
  • 3,429
  • 2
  • 24
  • 35