I have a problem using Media Player to play a number of parts of .wav-files after each other. While one part is being played I don't want the program to wait.
If I set
Notify := true;
Wait := False;
I get no sound at all.
What's the trick?
Setting Wait := True; and not using Notify gives me tha sound, but the the computer is frozen until play is done.
Every time OnNotify event is called I set Notify := true and Wait := False. Then I define a new sound and "Play", but it seems like all sounds are just passed, without I hear a sound.
Also I get a notify event in much less the time it should take to play my sound file. I specify start and end times in a sound file.
It seems like unless I set Wait := True there will be no sound. This however means the program can not do anything else while a sound is played. Is that realy the case??
Nop! If mediaplayer behaves like this, acept it an try it other way: Create a new thread that launch the sound with wait:= true, when THIS thread recover the control, it can set a global variable to signal it is finish to the main thread.
-Make another thread, and call the media player.
-This thread, on completion, call a procedure or set a variable to true.
-The thread suicide.
When this variable is set to true, internally it can be a proerty with a write method, so basically, the thread calls a method, then die.
You can play the next sound after this method is called, and, in the menawhile, your app is live and working as expected.
No, I don0t use threads usually, but creating a new thread and playing the media player from it is like dividing your app. into 2 different tasks, one is the main one, and the other is the one that launch mediaplayer and has to wait until it finish.
Is like in firefox: While one tab is bussy, the others are not, and the main thread (the menus and so) are running even if all the tabs are bussy. FDirefox uses 1 thread per tab + a main thread.
Anyway, you should have to look for TThread help or use google, I always managed to live without it, but it is a good resource is you get used to this (and you can, for instance, use several CPU from your app using it!).