Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK .NET / Sound.Playing does not work

Author
Message
aerostudios
14
Years of Service
User Offline
Joined: 20th May 2009
Location: Oklahoma City OK (USA)
Posted: 16th Nov 2011 15:58
I have converted about 90% of my DBPro app using the DGDK.NET now, but the <sound>.playing call does not work. Once my sound starts playing, the <sound>.playing property is set to true, and even if the sound completes, the <sound>.playing property never changes to false.

I had set up Do..Loops to exit once the sound playing is complete. But since the variable never changes to false, it becomes an endless loop.

For example;

Sound.play
Do
If Not Sound.Playing then
Exit Do
endif
loop

I have resorted to simple DarkGDK.Core.Wait statements to compensate for the length of time of the sound file by just pausing the app. But, it would be much better to check the .playing boolean instead. Any ideas?

Russell B. Davis/aerostudios
Chris Tate
DBPro Master
15
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 18th Nov 2011 14:40
Hmm, not sure why Sound.Playing does not return false when it has stopped.

What you are doing with the Wait command does the trick, but is not ideal.

If you need to run code during the waiting period, use the system time:

EndTime = Now.AddSeconds( N )
Do
---
Until EndTime <= Now

jojoofu
15
Years of Service
User Offline
Joined: 23rd Feb 2009
Location: Where ever Carmen Sandiego is
Posted: 18th Nov 2011 16:37 Edited at: 18th Nov 2011 16:39
Did you set the sound to looping ? If you did it will always be playing and therefore never return false. Could I see some more code? That way I might be able to help.

Also I wouldn't use separate loops for each sound. You should check to see if the sound is playing through each render loop. In fact almost everything in the game should be checked in that one loop.

" The best slaves are the ones who think they are free. "
aerostudios
14
Years of Service
User Offline
Joined: 20th May 2009
Location: Oklahoma City OK (USA)
Posted: 18th Nov 2011 17:02 Edited at: 18th Nov 2011 17:03
@jojoofu

I guess you didn't see my code fragment at the start of this post. It's pretty simple. I do understand the difference between .LOOP and .PLAY.



I have been using the same approach with numerous sound files. They all fail to respond as expected.

Russell B. Davis/aerostudios
jojoofu
15
Years of Service
User Offline
Joined: 23rd Feb 2009
Location: Where ever Carmen Sandiego is
Posted: 18th Nov 2011 18:41
This will help me more with the problem. Instead just tell me what type of game you are trying to build and when said sounds are playing. Maybe then I can help you come up with a practical approach to the problem.

" The best slaves are the ones who think they are free. "
aerostudios
14
Years of Service
User Offline
Joined: 20th May 2009
Location: Oklahoma City OK (USA)
Posted: 18th Nov 2011 18:49 Edited at: 18th Nov 2011 19:03
I appreciate the offer, but I don't need a practical approach to the problem. I need to know why this function does not behave correctly.
The only conclusion is this is a bug. The official product page for my game can be found here:

http://www.atcsimulator.com/airline-sharks.htm

And here on Facebook

http://www.facebook.com/pages/ATCsimulator/255616920083

It was already working as it should before converting from DB Pro to the DarkGDK.NET

Russell B. Davis/aerostudios
aerostudios
14
Years of Service
User Offline
Joined: 20th May 2009
Location: Oklahoma City OK (USA)
Posted: 18th Nov 2011 18:58
@Chris,

I even tried to use a Boolean this way;



Still no joy. So, I'm using just timed pauses and its working okay, just would prefer the command to work as expected.

I've sent a message to Apex, and no response. I guess we're kinda on our own with this SDK.

Russell B. Davis/aerostudios
jojoofu
15
Years of Service
User Offline
Joined: 23rd Feb 2009
Location: Where ever Carmen Sandiego is
Posted: 19th Nov 2011 18:21
I'm not sure why it isn't working. I use the playing boolean in my code and it works fine. Here is an example.

While DarkGDK.Engine.LoopGDK()

If GunSound.Playing = True Then
'do nothing
Else
GunSound.Play()
End If

End While

The only difference between the two code chunks is that I'm checking all my sounds in the main loop instead of doing an individual loop for each sound.

I do have one more question. Are you checking your sound in the main thread or using a second thread ? I really can't put a finger on why your code isn't working.

" The best slaves are the ones who think they are free. "
aerostudios
14
Years of Service
User Offline
Joined: 20th May 2009
Location: Oklahoma City OK (USA)
Posted: 19th Nov 2011 21:48
@jojoofu

I have more than 50 sound files to deal with. My code simply starts the sound playing. My logic needs to detect when it has stopped playing, not if it is playing.

The way things are behaving, any sound.play is false until you execute its play command. Once you do, it appears the .play property never changes to false, if after the sound has stopped on its own.

So, the thread doesn't matter. Once I start a sound playing, my code needs to wait until it has completed before moving on. That is why I am using a Do Loop. It is looping as long as Sound.play is true.

The only time after playing it reports false, is if I force the stop command.

The only way to use that approach is if I know when it should stop based upon its length; which there is nothing that will give me the length of the sound being played. Unless you know of such a method.

So, try the example code I gave you and see if you experience the same result.

Execute a Sound.Play command and then check for Sound.Playing = False, instead of true.

Russell B. Davis/aerostudios
jojoofu
15
Years of Service
User Offline
Joined: 23rd Feb 2009
Location: Where ever Carmen Sandiego is
Posted: 20th Nov 2011 20:31
I have some good news and some bad news. First the good news. I figured out why your code doesn't work.

Your code isn't working because you are not allowing the game engine to update. Everything in the engine including the audio update in the DarkGDK.Core.Sync() command. Basically you start the sound which set the playing variable to true. However the playing variable will not be updated again until the sync command is called. Even the sound is finished the playing variable will remain the same until you call the sync command. Now the bad news.

This does mean you will have to modify your code some and I'm sure you can work around it. I came up with this which worked perfectly for me when playing sounds.

Gun.Play()
While Gun.Playing
DarkGDK.Core.Sync()
End While

And there you have it. Good luck and let me know if this helps you.

" The best slaves are the ones who think they are free. "
aerostudios
14
Years of Service
User Offline
Joined: 20th May 2009
Location: Oklahoma City OK (USA)
Posted: 20th Nov 2011 20:38
Hey thanks. that's not a bad thing, I'll just need to add the Sync command inside my loop. That should solve the problem.

I'll let you know.

Russell B. Davis/aerostudios
aerostudios
14
Years of Service
User Offline
Joined: 20th May 2009
Location: Oklahoma City OK (USA)
Posted: 20th Nov 2011 20:45
I just changed my code to this;



Worked like a champ. thanks for figuring that out. I'll have to remember, the sync is more important when developing with the .NET platform vs. the DB Pro language product.

Russell B. Davis/aerostudios
jojoofu
15
Years of Service
User Offline
Joined: 23rd Feb 2009
Location: Where ever Carmen Sandiego is
Posted: 20th Nov 2011 20:51
Glad it worked for you

I'm almost done with a complete library for Dark GDK .net that will sum most of the complicated tasks up in a few lines of code.

" The best slaves are the ones who think they are free. "

Login to post a reply

Server time is: 2024-04-20 00:45:38
Your offset time is: 2024-04-20 00:45:38