Adventure Game Studio | Forums

AGS Support => Beginners' Technical Questions => Topic started by: Two Tales on 24 Aug 2019, 20:24

Title: Is music playing
Post by: Two Tales 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.
Title: Re: Is music playing
Post by: Khris on 25 Aug 2019, 20:35
Let's say you have a global AudioChannel* variable named  bgm.
Once you do
Code: Adventure Game Studio
  1.   bgm = aSomeBackgroundMusic.Play();
you can now do something like
Code: Adventure Game Studio
  1.   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
Title: Re: Is music playing
Post by: Crimson Wizard 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. }
  10.  

Usage:
Code: Adventure Game Studio
  1. if (IsSoundTypePlaying(eAudioTypeMusic))
  2.  
Title: Re: Is music playing
Post by: Two Tales on 26 Aug 2019, 14:18
Thanks to both of you. This is really helpful.