Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Two Tales on Sat 24/08/2019 20:24:25

Title: Is music playing
Post by: Two Tales on Sat 24/08/2019 20:24:25
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 Sun 25/08/2019 20:35:57
Let's say you have a global AudioChannel* variable named  bgm.
Once you do
  bgm = aSomeBackgroundMusic.Play();
you can now do something like
  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 Sun 25/08/2019 21:35:42
If you need to know if *any* music plays, then
Code (ags) Select

bool IsSoundTypePlaying(int sound_type)
{
     for (int i = 0; i < System.AudioChannelCount; i++)
     {
          AudioChannel *ch = System.AudioChannel[i];
          if (ch.IsPlaying && ch.PlayingClip.Type == sound_type) return true;
     }
     return false;
}


Usage:
Code (ags) Select

if (IsSoundTypePlaying(eAudioTypeMusic))
Title: Re: Is music playing
Post by: Two Tales on Mon 26/08/2019 14:18:48
Thanks to both of you. This is really helpful.