Is music playing

Started by Two Tales, Sat 24/08/2019 20:24:25

Previous topic - Next topic

Two Tales

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.

Khris

Let's say you have a global AudioChannel* variable named  bgm.
Once you do
Code: ags
  bgm = aSomeBackgroundMusic.Play();

you can now do something like
Code: ags
  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

Crimson Wizard

If you need to know if *any* music plays, then
Code: ags

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

if (IsSoundTypePlaying(eAudioTypeMusic))

Two Tales

Thanks to both of you. This is really helpful.

SMF spam blocked by CleanTalk