resumeChannel method

dynamic resumeChannel(
  1. int channelId
)

Resumes a paused sound on the specified channelId.

If the channel is not paused, this method does nothing.

  • channelId: The ID of the channel to resume.

Implementation

resumeChannel(int channelId) {
  if (audioContext.state == 'suspended') {
    audioContext.resume();
  }
  var channel = _channels[channelId];
  if (channel.state != ChannelState.paused) {
    return;
  }

  channel.sourceNode = audioContext.createBufferSource();

  channel.sourceNode!
    ..buffer = channel.sound!.buffer
    ..playbackRate.value = channel.rate
    ..loop = channel.loop
    ..connect(channel.pannerNode)
    ..onended =
        (Event e) {
          channel.sourceNode = null;
          channel.state = ChannelState.stopped;
        }.toJS;

  channel
    ..startTime = audioContext.currentTime
    ..sourceNode!.start(0, channel.offset)
    ..state = ChannelState.playing;
}