Author Topic: Is music playing  (Read 238 times)

Is music playing
« on: 24 Aug 2019, 20:24 »
How do I script to tell if music is playing in the music channel/folder.
I'm trying to do something like: If music playing {do nothing} else {aSomething.Play();}
I've tried playing around with the IsPlaying property and with Type property after looking in manual. But my experiments are failing.


  • partook in silencing a crtitc despite facts
    • Lifetime Achievement Award Winner
    • I can help with play testing
    • I can help with scripting
    • I can help with translating
    • Khris worked on one or more games that was nominated for an AGS Award!
Re: Is music playing
« Reply #1 on: 25 Aug 2019, 20:35 »
Let's say you have a global AudioChannel* variable named  bgm.
Once you do
Code: [Select]
  bgm = aSomeBackgroundMusic.Play();you can now do something like
Code: [Select]
  if (bgm.IsPlaying) ...
Here's a thread about having a piece of music play continuously in several rooms: https://www.adventuregamestudio.co.uk/forums/index.php?topic=50363.msg
Fail at Floaty Rog' now!  still having to deal with what games are going through

Re: Is music playing
« Reply #2 on: 25 Aug 2019, 21:35 »
If you need to know if *any* music plays, then
Code: Adventure Game Studio
  1. bool IsSoundTypePlaying(int sound_type)
  2. {
  3.      for (int i = 0; i < System.AudioChannelCount; i++)
  4.      {
  5.           AudioChannel *ch = System.AudioChannel[i];
  6.           if (ch.IsPlaying && ch.PlayingClip.Type == sound_type) return true;
  7.      }
  8.      return false;
  9. }

Code: Adventure Game Studio
  1. if (IsSoundTypePlaying(eAudioTypeMusic))

Re: Is music playing
« Reply #3 on: 26 Aug 2019, 14:18 »
Thanks to both of you. This is really helpful.