Playing .avi files many times causes problems

I have an application which plays .avi files. When I get a notification that the movie has ended I want to start another movie and so on. This works well for 5-6 hours (each movie lasts approx 30 seconds) then the program locks up. The code in the OnNotify event looks something like the following

   MoviePlayer.Wait := true;
   MoviePlayer.Notify := false;

   MoviePlayer.Close;

   MoviePlayer.FileName := 'plate.avi';

   MoviePlayer.Open;

   MoviePlayer.Wait := false;
   MoviePlayer.Notify := true;

   MoviePlayer.Play;

I have displayed a bunch of stuff about the memory and heap status each time the movie ends but nothing obvious shows up (I accept this may be due to my lack of skill in interpretation).

This is the first time I've used this service so I'm unsure whether I can e-mail you my test program.

Thanks in advance.

Regards
p_oliverAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

p_oliverAuthor Commented:
Edited text of question
0
d003303Commented:
Yo,
seems that you are getting a stack overflow after this 5-6 hours. So, how does this happen ?
You hook into an event handler. This event handler is called by the component. In the handler, you change the state of the component. Then you leave the handler, and the call flow is a little bit messed up, because the notification handler returns to a different component state. This often happens in components that work asynchronously. Internally, the component works with messages, but the messages can not be read in the right order.
Long answer, short solution : post some private messages to yourself, so all messages will be in the right order.

Write a private message handler for your app, like

  TForm1 = class(TForm)
// stuff...
  public
    procedure WM_MyMessage(var Msg: TMessage); message WM_USER + 1;
// stuff...
  end;

// stuff...

procedure TForm1.MoviePlayerOnNotify(Sender: TObject);
begin

   MoviePlayer.Wait := true;
   MoviePlayer.Notify := false;

   MoviePlayer.Close;

   PostMessage(Self.Handle, WM_USER + 1, 0, 0);

end;

procedure TForm1.WM_MyMessage(var Msg: TMessage);
begin

   MoviePlayer.FileName := 'plate.avi';

   MoviePlayer.Open;

   MoviePlayer.Wait := false;
   MoviePlayer.Notify := true;

   MoviePlayer.Play;

end;


Slash/d003303
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
p_oliverAuthor Commented:
My apologies for the time taken to try your suggestions. I like
your thinking but unfortunately it only produced a slight
improvement - the program locked up after approx 7 hours
rather than the 5-6 hours previously.

I am experimenting further and have removed all code from
the OnNotify handler with the exception of the PostMessage.

The message handler now does all the manipulation of the
media player. I did this because it occured to me that switching
the notify condition off and on within the OnNotify handler might
be causing some nasty or recursive effect.

I greatly appreciate your input, if you have any other ideas to
suggest I would be most grateful.


0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.