recreateNode method
void
recreateNode()
Implementation
void recreateNode() {
if (_currentUrl == null) {
return;
}
final p = player = AudioElement(_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 = JsAudioContext();
final source = audioContext.createMediaElementSource(player!);
_stereoPanner = audioContext.createStereoPanner();
source.connect(_stereoPanner!);
_stereoPanner?.connect(audioContext.destination);
// Preload the source
p.load();
}