stopChannel method

dynamic stopChannel(
  1. int channelId
)

Stops the sound playing on the specified channelId.

If the channel is already stopped, this method does nothing.

  • channelId: The ID of the channel to stop.

Implementation

stopChannel(int channelId) {
  var channel = _channels[channelId];
  if (channel.state == ChannelState.stopped) return;

  if (channel.state == ChannelState.playing) {
    channel.sourceNode?.onended = null;
    try {
      channel.sourceNode?.stop(0);
    } catch (e) {
      //ignore errors
    }
    channel.sourceNode = null;
  }
  channel.state = ChannelState.stopped;
}