Author Topic: Check if audio is playing  (Read 480 times)

PedroSanchez

  • Posts: 3
Check if audio is playing
« on: 13 Apr '19 - 01:39 »
I am trying to figure out a way to check if audio is already playing so that it can not be played again (same audio repeating every key input) I am trying to use ChannelIsActive with no success. Ive tried using the code shown below, as well as !BASS_ACTIVE_PLAYING, basically a variation of everything. But what ever I try the audio does not playing when trying to use it in conjuntion with ChannelIsActive, I am not sure if I am using it correctly, or if maybe ChannelIsActive is not returning anything.....(The audio does work on its own though, it has been tested)

Code: [Select]
HCHANNEL ch = BASS_SampleGetChannel(sample, FALSE);
if (BASS_ChannelIsActive(ch) == BASS_ACTIVE_STOPPED)
{
BASS_ChannelPlay(ch, true);
}

Ian @ un4seen

  • Administrator
  • Posts: 22121
Re: Check if audio is playing
« Reply #1 on: 15 Apr '19 - 13:02 »
New sample channels from BASS_SampleGetChannel start in a paused state (BASS_ACTIVE_PAUSED), so your "if" statement will always be false if the BASS_SampleGetChannel call was successful. If that call was unsuccessful (eg. no free channels) then the "ch" handle will be invalid (0) and the BASS_ChannelPlay call will fail.

If you want a sample to be played only once at a time and never restarted, then you could set max=1 and don't use any BASS_SAMPLE_OVER_XXX flags in the BASS_SampleLoad call. Then if the BASS_SampleGetChannel call fails, that means the sample is already playing.

PedroSanchez

  • Posts: 3
Re: Check if audio is playing
« Reply #2 on: 15 Apr '19 - 15:58 »
While trying to figure this out I thought of an issue that might occur because of it. If I only have one HChannel and nothing else. And I have multiple audio files that play through that one channel, if I set it, like I am trying to do above, that will stop all other audio right, it will only play the one audio file and nothing else at the same time, correct? Thank you for the help, it is appreciated.

Also the set max you mention is that something in BASS, or are you meaning that just as a variable?
« Last Edit: 15 Apr '19 - 16:07 by PedroSanchez »

Ian @ un4seen

  • Administrator
  • Posts: 22121
Re: Check if audio is playing
« Reply #3 on: 15 Apr '19 - 16:57 »
Each sample has its own channels, so multiple samples won't interfere with each other. The number of channels is determined by the "max" parameter in the BASS_SampleLoad call (that's the "max" I was referring to).