ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Control the position of video using scrollbar
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

zhengyuanyi27

58 Posts

Posted - Nov 17 2019 :  03:48:11  Show Profile  Reply
In order to use a scrollbar to control the progress when playing an avi video (In another words, I want to drag the button of the scrollbar to control the position of the video), I used the following code to open an AVI file and set the max of scrollbar to the max frame number of the video.

with ImageEnVect2.IO.DShowParams do
              begin
                  if State = gsRunning then
                  begin
                      Stop;
                      Disconnect;
                  end;
                    FileInput:=filepath;
                    EnableSampleGrabber := true;
                    RenderAudio := true;
                    Connect;
                    if Show_Position_By_Frame then
                    ImageEnVect2.IO.DShowParams.TimeFormat := tfFrame;
                    Position := 0;
                    Pause; 
                    ImageEnVect2.IO.DShowParams.Run;

                 TotalFrames:=0;
                 TotalFrames:=ImageEnVect2.IO.OpenMediaFile(FilePath);
                 Scrollbar1.Max:=TotalFrames;

              end;

And I wrote the following code for the onChange event of the scrollbar.

procedure TForm1.ScrollBar1Change(Sender: TObject);
begin
    CurrentFrameNo:=Scrollbar1.Position;
    caption:=inttostr(CurrentFrameNo);
    ImageEnvect2.IO.DShowParams.Pause;
    ImageEnvect2.IO.LoadFromMediaFile(CurrentFrameNo);
end;

The above code works well (I mean the frame stops at the frame of scrollbar's position), but when I add one more code to the event ( ImageEnvect2.IO.DShowParams.Run; ), it seems the video doesn't play the video from where the video stops. I mean it seems that it doesn't play the video from the position the scrollbar's position. It seems the position of the scrollbar is different from the position the video stops. Could somebody tell me what's wrong? Thanks!!

procedure TForm1.ScrollBar1Change(Sender: TObject);
begin
    CurrentFrameNo:=Scrollbar1.Position;
    caption:=inttostr(CurrentFrameNo);
    ImageEnvect2.IO.DShowParams.Pause;
    ImageEnvect2.IO.LoadFromMediaFile(CurrentFrameNo);

    ImageEnvect2.IO.DShowParams.Run;  
end;

zhengyuanyi27

58 Posts

Posted - Nov 17 2019 :  04:32:37  Show Profile  Reply
I found the problem is:
The codes of "ImageEnvect2.IO.LoadFromMediaFile(CurrentFrameNo);" can let Imageenvect2 to load the frame at the scrollbar's position, but when excecuting "ImageEnvect2.IO.DShowParams.Run", it resumes to the frame which it pauses, NOT from the frame number to the Scrollbar's position. For example, the video pauses at the 3rd frame and I use "ImageEnvect2.IO.LoadFromMediaFile(100)" to load the image of the 100th frame, and when aplly "ImageEnvect2.IO.DShowParams.Run", the video still starts from the 3rd frame.
Thus, the question is more simple now: How to set the video to start to play at a given frame number?
Thanks!!
Go to Top of Page

xequte

38175 Posts

Posted - Nov 18 2019 :  18:51:14  Show Profile  Reply
Hi

Use position to specify the position to run from, e.g.

// Run video from 5 second mark
ImageEnView1.IO.DShowParams.Position := 50000000;
ImageEnView1.IO.DShowParams.Run;

Nigel
Xequte Software
www.imageen.com
Go to Top of Page

zhengyuanyi27

58 Posts

Posted - Dec 29 2019 :  00:41:25  Show Profile  Reply
Thanks for your help!
So you mean that we can't directly set the video to start to play at a given frame number unless we calculate the time position of the given frame?
Go to Top of Page

xequte

38175 Posts

Posted - Jan 01 2020 :  17:28:53  Show Profile  Reply
Actually the DShowParams.Position should be the current time format, e.g. if it's set to tfFrame, those values should be frame values.

Nigel
Xequte Software
www.imageen.com
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: