obtainFreeChannel method

int obtainFreeChannel(
  1. List<int>? targetChannels
)

Finds and returns the ID of a free (stopped) audio channel.

  • targetChannels: An optional list of channel IDs to check. If null, all channels (_allChannels) are checked.

Returns the ID of a free channel, or -1 if all specified/available channels are in use.

Implementation

int obtainFreeChannel(List<int>? targetChannels) {
  targetChannels ??= _allChannels;
  for (var channel in targetChannels) {
    if (channel >= 0 && channel < _channels.length && _channels[channel].state == ChannelState.stopped) {
      return channel;
    }
  }
  return -1;
}