Page 1 of 1

Problems with LiveAudioPlayer and Async := True

PostPosted: October 1st, 2006, 8:20 am
by pawbyrialsen
Hi

Im using LiveAudioPlayer in Delphi 2006 to build an "OnlinePlayer" (Datamodule with the liveAudioPlayer component added at designtime). It is important to me that the main thread isn't stalled by the Online Player thus property Async is set to True, instead of implementing the entire Online Player in my own thread.

The problem is that when I do code like this from my mainthread:

OnlinePlayer.LiveAudioPlayer.Active := True

Then i except to get the "OnDataPtr" event afterwards. This happens most of the times but not always. Sporadically I dont get the "OnDataPtr" event at all, and this is ofcourse a very bad situation for me.

If nessesary I can provide a sample application that demonstrates the problem, but I guess that someone must have seen this happens too.

Finally please notice that setting Async := False, I always get the "OnDataPtr" event.

/Paw

PostPosted: October 1st, 2006, 4:22 pm
by Kambiz
Providing a sample application will help me a lot to figure out and resolve the problem.

By the way, before sending me the code, verify your event handlers are thread safe.

Thank you.

PostPosted: October 1st, 2006, 6:04 pm
by pawbyrialsen
Hi,

Okay, here goes a very simple example. Just start the application and press Activate until you detect an situation where OnData doesn't occur.

Your might have to "activate" a few times:)

/Paw

PS: After posting this message I tried running the .exe directly in Windows (Delphi closed). It seemed like OnData always occurs then. Hope this gives you an clue to what might be wrong.

PostPosted: October 2nd, 2006, 12:39 pm
by Kambiz
I don't have BDS 2006, but checked your code out with BDS 2005 and Delphi 6, and everything worked as expected.

PostPosted: October 2nd, 2006, 1:48 pm
by pawbyrialsen
Also if you hold ENTER button down for a minut or two (when Activate button is the one with focus)??

/Paw

PostPosted: October 4th, 2006, 8:25 am
by Kambiz
Even in this case everything works fine.

Anyway, you have to prevent re-occurrence of the OnClick event.

PostPosted: October 12th, 2006, 7:55 pm
by pawbyrialsen
Hi,

It's been a while but I have done som testing parallel with my other tasks, and finally i succeded to find the problem and also made a temporary solution that fixes the problem for now.

The problem is inside the "InternalOpen" method in TWaveAudioOut class. To be more precise the problem is after you call CreateCallback. You have to guarantee that the thread is actually running (execute is started) before you call WaveOutOpen, Otherwise Windows messages can be lost. And thats excatly what happened with my developer machine in D2006. I have also been able to recreate the problem in D2005 on another machine, but on my D2006 I can recreate it all the time.

So my best advice is to make an Event (CreateEvent) and then signal this event from TWaveThread.Execute. Then you will be able to call WaitForSingleObject between the call to CreateCallback and WaveOutOpen. (I have set Timeout to 1000 ms). My execute looks like this:

Code: Select all
procedure TWaveThread.Execute;
var
  MSG: TMSG;
begin
  // Initiate thread messageque and signal thread is running and ready to recieve messages
  PeekMessage(MSG, 0, 0, 0, PM_NOREMOVE);
  WaveAudioIO.SignalEvent;
  while GetMessage(MSG, 0, 0, 0) do
    WaveAudioIO.ProcessWaveMessage(MSG.Message, PWaveHdr(MSG.lParam));
  WaveAudioIO.ThreadHandle := 0;
end;


Hopefully you see what I mean and maybee you will be able to make an update to the package.

By the way, when looking at the web searching for hints to my problem I found the folowing article. Thought it might be of interrest to you:)

http://www.tech-archive.net/Archive/Dev ... /0130.html

/Paw
Code: Select all

PostPosted: October 12th, 2006, 10:32 pm
by Kambiz
Paw, thank you very much for this valuable information.

PostPosted: October 13th, 2006, 1:41 pm
by pawbyrialsen
Have you any idea if a new version is to expect in the near future or do you prefer to upgrade in larger bundles?

/Paw

PostPosted: October 13th, 2006, 9:24 pm
by Johnny_Bit
you should know answer b now: when he got the time

PostPosted: October 18th, 2006, 4:43 pm
by Kambiz
Johnny_Bit is absolutely right.

Hopefully in the next few weeks I can find time to release the updates for WA Package and SB Pro component.