## Problems with LiveAudioPlayer and Async := True

Please post bug reports, feature requests, or any question regarding the DELPHI AREA projects here.

### Problems with LiveAudioPlayer and Async := True

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
pawbyrialsen
Active Member

Posts: 5
Joined: October 1st, 2006, 7:55 am

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.
Kambiz

Kambiz

Posts: 2429
Joined: March 7th, 2003, 7:10 pm

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.
Attachments
LiveAudioDemo.zip
pawbyrialsen
Active Member

Posts: 5
Joined: October 1st, 2006, 7:55 am

I don't have BDS 2006, but checked your code out with BDS 2005 and Delphi 6, and everything worked as expected.
Kambiz

Kambiz

Posts: 2429
Joined: March 7th, 2003, 7:10 pm

Also if you hold ENTER button down for a minut or two (when Activate button is the one with focus)??

/Paw
pawbyrialsen
Active Member

Posts: 5
Joined: October 1st, 2006, 7:55 am

Even in this case everything works fine.

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

Kambiz

Posts: 2429
Joined: March 7th, 2003, 7:10 pm

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
pawbyrialsen
Active Member

Posts: 5
Joined: October 1st, 2006, 7:55 am

Paw, thank you very much for this valuable information.
Kambiz

Kambiz

Posts: 2429
Joined: March 7th, 2003, 7:10 pm

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
pawbyrialsen
Active Member

Posts: 5
Joined: October 1st, 2006, 7:55 am

you should know answer b now: when he got the time
Johnny_Bit
VIP Member

Posts: 455
Joined: June 15th, 2003, 9:56 am

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.
Kambiz

Kambiz