Delphi my timecode doesnt sync up properly

Hello,

I have a program which displays video and allows me to seek to a word in the video. In record mode, I have a timer running. When I type a word and hit enter, my program will note how many seconds has since elapsed and store the word and the seconds elapsed into a VirtualStringTree.

In playback mode, it is seeks to the right frames for up to roughyl 5-6 times then all of a sudden is out of sync by a few seconds which is driving me nuts.

I am using the TMPlayer since it was available for free.
http://www.felix-colibri.com/papers/graphic/delphi_video_player/delphi_video_player.html#tmplayer_video_player
My code basically retrieve the timing for the word I clicked on and seeks to that position.
Then seeks 4 seconds before the word so that I actually hear the word.

I tried with seconds, then felt that if I change to milliseconds, I might be able to sync it better but I dont think it may any difference.
Anyone can help
var
Data    : PNodeData;
s       : String;
distancetotravel : double;
begin
if KeyLoggerAudioTiming.FocusedNode=nil then //no selected node
exit;
Data := KeyLoggerAudioTiming.GetNodeData(KeyLoggerAudioTiming.FocusedNode);

// Go forward

if milliseconds < StrToInt(Data.DictionaryWord) then
begin
MultimediaTimer1.Enabled := false;
  distancetotravel := (StrToFloat(Data.DictionaryWord) - milliseconds) / 250;

  MPlayer1.SendSeek(distancetotravel-4, false);

  milliseconds := StrToInt(Data.DictionaryWord)-4000;
  MultimediaTimer1.Enabled := true;
end;

// go backwards
if milliseconds > StrToInt(Data.DictionaryWord) then
begin
MultimediaTimer1.Enabled := false;
  distancetotravel := (milliseconds - StrToInt(Data.DictionaryWord)) / 1000;
  MPlayer1.SendSeek(-distancetotravel-4, false);
  milliseconds := StrToInt(Data.DictionaryWord)-4000;
MultimediaTimer1.Enabled := true;
end;
AivsCoderAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
samenglishConnect With a Mentor Commented:
Rounding error? Too big to fit in Int variable? If you want better accuracy, stick to double instead of integers and minimise converting from one type to another. Sounds like a code design issue. I'd advise you to encapsulate (or refactor) your code so that each search operation executes with maximum reliability. Don't reuse any variables for subsequent calls. It's left overs from previous calls that usually end up compromising the results of subsequent operations. Consider either a proper OO implementation with internal fields, or if you prefer to do it the old fashioned way then make sure all the variables are reset to their original values before subsequent calls to the same code that relies on those variables. Also write down the times when you're recording and check that the correct time is being recorded (I mean check against a seperate timer object or stopwatch - don't assume the MPlayer component is returning the correct time). Hope that helps, sorry I can't delve into the code itself. Good luck.
0
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
Just a guess but could be it a difference in these divisions by case?

// Go forward
if milliseconds < StrToInt(Data.DictionaryWord) then
begin
MultimediaTimer1.Enabled := false;
  distancetotravel := (StrToFloat(Data.DictionaryWord) - milliseconds) / 250; //why by 250????

// go backwards
if milliseconds > StrToInt(Data.DictionaryWord) then
begin
MultimediaTimer1.Enabled := false;
  distancetotravel := (milliseconds - StrToInt(Data.DictionaryWord)) / 1000;
0
 
Ephraim WangoyaCommented:

Why don't you make the times to be relative to the start time of the video
0
 
AivsCoderAuthor Commented:
Code example would have been nice. Thanks anyways
0
All Courses

From novice to tech pro — start learning today.