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;