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.

AppGameKit Classic Chat / How do I stop an instance of a sound?

Author
Message
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 18th Jul 2013 22:14
Hi all,

I need a little help with the sound commands (and sorry if it has already been asked before - I did have a quick look).

If I have multiple instances of a sound playing, how do I selectively stop just one instance? The stopsound command stops every instance of that particular sound at once which is not the effect I am after.

I am keeping track of which sounds are playing (the same sound can be playing multiple times in this list), and I need to be able to stop the individual instance of a sound that has been playing for the longest time before I start playing the next sound in order to stop the wav player system getting over loaded with too many sounds playing at once (which rather than prematurely ending already playing sounds, it simply prevents further sounds from starting until the others have ended - whose idea was that? Yuk!). Unfortunately the sound number used in the stopsound command stops every instance of that sound, not just the longest playing instance of it.

I really hope there is a way to do this, otherwise my really nice multi-touch pan-drum simulator is ruined

Thanks!

Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 18th Jul 2013 22:32
Each time you load a sound to play (LoadSound), you either provide a new id or store the one returned by the call.

Then you decide which one you want to stop and call StopSound with that id.

PlaySound called with a given id will only create one instance of that sound (as identified by that id) playing at a time. Multiple calls with the same id simply restart it. They do not create a new instance of the sound playing.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 18th Jul 2013 22:59
Really? Then what does GetSoundInstances do? The manual says:

integer GetSoundInstances( iID )
Returns the number of instances of this sound ID that are currently playing or looping. This is exactly the same as GetSoundsPlaying.

surely it would only ever return 0 or 1 if that's the case? (maybe it does! - I haven't done any testing).

Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 18th Jul 2013 23:35
Huh, I never noticed that command (or GetSoundsPlaying).

I always assumed that there was only one instance of PlaySound for any given ID.

This might explain some issues that people have had.

And it sounds like there should be a return value for PlaySound to let you manipulate each instance, if that is what they do.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 19th Jul 2013 18:17
I've managed to work around the problem by using shorter samples (so they now stop before overloading the wav playing system). It's not a great solution, but gets the app working properly. I have my google play publishers account all set up now too! Yay

Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 19th Jul 2013 18:37
Good luck and Happy Programming.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 20th Jul 2013 13:57
Quote: "PlaySound called with a given id will only create one instance of that sound (as identified by that id) playing at a time. Multiple calls with the same id simply restart it. They do not create a new instance of the sound playing."


Nope, AppGameKit will not restart a playing sound, it will create a new instance on top of any currently playing instances.

This is my current project, check it out! [href]forum.thegamecreators.com/?m=forum_view&t=204576&b=8[/href]
This is my website, check it out! [href]http:\\www.TeamDefiant.co.uk[/href]
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 20th Jul 2013 19:54
Quote: "Nope, AppGameKit will not restart a playing sound, it will create a new instance on top of any currently playing instances."

So I now understand. But the command really should return a reference and there should be a command to stop a specific instance.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
fog
21
Years of Service
User Offline
Joined: 5th Oct 2003
Location: Newcastle, England
Posted: 20th Jul 2013 20:31 Edited at: 20th Jul 2013 20:31
If using Tier 2 there are a few extra command, one of which IIRC looks like it will stop all instances of a given sound.

Can't check from here but have a rummage in "cSoundMgr.h"....or something like that.

(I assume AppGameKit uses these behind the scenes to delete all instances and avoid conflicts when you call DeleteSound()....possibly )

Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 20th Jul 2013 21:27
I think the original issue is that StopSound does stop all instances and the desire is to stop only some of them.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 23rd Jul 2013 15:30
Exactly. I wanted to be able to selectively stop a specific instance of a sound rather than stopping all instances of a particular sound all at once. I have accepted I can't do this as a limitation of AppGameKit, worked around it, and moved on. Thanks for everyone who took time to help.



Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 23rd Jul 2013 16:32 Edited at: 23rd Jul 2013 16:35
what about to limit the playing samples
if GetSoundsPlaying(id)<5 then PlaySound(id) else Play noise

if think if you play more samples then the "card" can play you
don't hear the new one or the first will stop.
JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 23rd Jul 2013 17:45
http://www.appgamekit.com/documentation/Reference/Sound/StopSound.htm

StopSound() should stop an individual sound, not all of them.

-- Jim DO IT FASTER, EASIER AND BETTER WITH AppGameKit FOR PASCAL
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 23rd Jul 2013 17:59
The issue is that PlaySound can be used on a given sound ID to produce multiple instances of that sound playing.

And the desire is to stop just one instance of the sound, not all.

StopSound stops all instances of the sound playing.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 23rd Jul 2013 18:02
That seems a little weird!

-- Jim DO IT FASTER, EASIER AND BETTER WITH AppGameKit FOR PASCAL
DVader
20
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 23rd Jul 2013 19:02 Edited at: 23rd Jul 2013 19:43
I think people may be thinking of the music commands here. As far as I know stopping a sound is easy, it is music that is more of a blanket thing.

This plays two identical sounds which I have loaded into separate ID's. I then proceed to stop the first sound when pressing space. Works fine, the other sound is still playing, but you can easily hear the other has stopped.
Music on the other hand, works differently, as there is no ID in the stopmusic() command.

I may be missing something, as I have only skipped over the thread, but I'm not sure of the issue, at least on a PC. On android etc, there are several sound issues, or at least there where.

Edit - Having looked at the thread more in detail, I think I see what the issue is. Only way I can think round it is to perhaps have several ID's made that it can count through. So say 10 for example of each sound. So each time you play the sound, it moves to the next, and then loops back when it goes past 10. Pity there isn't a clone sound command to reduce memory usage and loading time though. it is a cheat but would work I believe.

Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 23rd Jul 2013 22:21
@DVader. The command works as you expect it to as there are two sound ID's.



Running this, you will see that the command stops all instances of the same sound ID, which is exactly what the help says. You can play the same sound ID multiple times, but this command will stop them all.

This is my current project, check it out! [href]forum.thegamecreators.com/?m=forum_view&t=204576&b=8[/href]
This is my website, check it out! [href]http:\\www.TeamDefiant.co.uk[/href]
DVader
20
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 27th Jul 2013 14:28
Yes I realized that in my Edit. It is why I suggested loading multiple ID's of the same sound file. Not the best solution, but as far as I can see the only option that will allow it. That way you could stop each individual version of the sound with no problems.

Login to post a reply

Server time is: 2024-11-24 18:26:45
Your offset time is: 2024-11-24 18:26:45