Skip to main content

News

Topic: Play a sound multiple times without waiting for it to finish (Read 340 times) previous topic - next topic

Play a sound multiple times without waiting for it to finish
I'm trying to get it so that I can play a loaded Sound file multiple times (for example, playing a bullet firing sound quickly), but calling sound_obj.play(Mixer.Default) seems to block it script execution until it finishes. Is there a way to play sound objects asynchronously?
  • Last Edit: April 30, 2017, 09:12:02 pm by Eggbert

  • Fat Cerberus
  • [*][*][*][*][*]
  • Global Moderator
  • miniSphere Developer
Re: Play a sound multiple times without waiting for it to finish
Reply #1
Sound#play() shouldn't block.  The music module in particular specifically relies on it not blocking, so it's kind of weird if it is for you.

That said, a single Sound can only have one instance playing at a time - calling play() on it again will just restart it:

Code: [Select]

Sound#play([mixer]);

    Begins or resumes sound playback.  When called with no `mixer` argument,
    Sound#play() will resume playback for a paused sound.  Otherwise, the sound
    is started from the beginning on the specified mixer.


I should probably implement a SoundEffect API like Sphere 1.6.  Something to think about for the next miniSphere version, I guess. :)
  • Last Edit: April 30, 2017, 11:30:00 pm by Fat Cerberus
miniSphere 5.0b4 (stable: 4.8.8) - Cell compiler - SSj debugger - thread | on GitHub
For the sake of our continued health I very much hope that Fat Cerberus does not become skilled enough at whatever arcane art it would require to cause computers to spawn enourmous man eating pigs ~Rhuan

Re: Play a sound multiple times without waiting for it to finish
Reply #2
I think that might have been the issue then. Though it seems to have issues if it restarts it repeatedly .