[Solved] Sound Stop Callback

Just starting out? Need help? Post your questions and find answers here.
whax
Posts: 2
Joined: Wed Dec 16, 2020 11:14 am

[Solved] Sound Stop Callback

Post by whax »

Hello everyone

Asking a general question on how it's best handled to know if a sound has stopped or not. Right now I'm adding a Window Timer that queries every few ms with SoundStatus() if a sound has stopped or not but I'm questioning if this is is a viable method (it works well enough). But I'm wondering if this can be done with a callback as well (for example if a previous sound has stopped play the next one). Any tips for this?
Last edited by whax on Sun Jan 17, 2021 11:48 pm, edited 1 time in total.
User avatar
Peter
Posts: 1086
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: Sound Stop Callback

Post by Peter »

Code: Select all

Procedure PlaySound2(a, c = 0, b = 100, Callback = #Null)
  
  ! var a = v_a;
  ! var b = v_b;
  ! var c = v_c;
  
  !  // original SB-Code (spider_PlaySound()) with callback-call:
  !  "undefined" === typeof c && (c = 0);
  !  "undefined" === typeof b && (b = 100);
  !  var d, e;
  !  if (d = spider.sound.objects.Get(a))
  !      if (c & 2) {
  !          for (e = 1; 32 > e && d.channels[e]; e++)
  !              ;
  !          if (32 > e)
  !              return a = createjs.Sound.play(d.id, createjs.Sound.INTERRUPT_ANY, 0, 0, c & 1 ? -1 : 0, b / 100),
  !              d.channels[e] = a,
  !              a.addEventListener("complete", function(a) {
  !                  d.channels[e] = null
  !                  if (v_callback) v_callback(v_a);
  !              }),
  !              e
  !      } else
  !          return (a = d.channels[0]) ? (a.setPosition(0),
  !          a.setVolume(b / 100)) : (a = createjs.Sound.play(d.id, createjs.Sound.INTERRUPT_ANY, 0, 0, c & 1 ? -1 : 0, b / 100),
  !          d.channels[0] = a,
  !          a.addEventListener("complete", function(a) {
  !              d.channels[0] = null
  !              if (v_callback) v_callback(v_a);
  !          })),
  !          1;
  !  return 0
  
EndProcedure

Code: Select all

Procedure YourCallback(Sound)
  Debug "Sound " + Sound + " is ready"
EndProcedure

PlaySound2(YourSound, Flags, Volume, @YourCallback())
whax
Posts: 2
Joined: Wed Dec 16, 2020 11:14 am

Re: [Solved] Sound Stop Callback

Post by whax »

Hello Peter

Thank you very much, exactly what I was looking for. And thank you for your Leaflet + Tabulator Modules as well :)
Post Reply