recreateNode method

void recreateNode()

Implementation

void recreateNode() {
  final currentUrl = _currentUrl;
  if (currentUrl == null) {
    return;
  }

  final p = player = web.HTMLAudioElement();
  p.preload = 'auto';
  p.src = currentUrl;
  // As the AudioElement is created dynamically via script,
  // features like 'stereo panning' need the CORS header to be enabled.
  // See: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS
  p.crossOrigin = 'anonymous';
  p.loop = shouldLoop();
  p.volume = _currentVolume;
  p.playbackRate = _currentPlaybackRate;

  _setupStreams(p);

  // setup stereo panning
  final audioContext = web.AudioContext();
  final source = audioContext.createMediaElementSource(player!);
  _stereoPanner = audioContext.createStereoPanner();
  source.connect(_stereoPanner!);
  _stereoPanner?.connect(audioContext.destination);

  // Preload the source
  p.load();
}