Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions packages/audioplayers_web/lib/wrapped_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class WrappedPlayer {
web.HTMLAudioElement? player;
web.AudioContext? _audioContext;
web.MediaElementAudioSourceNode? _sourceNode;
web.GainNode? _gainNode;
web.StereoPannerNode? _stereoPanner;
StreamSubscription? _playerEndedSubscription;
StreamSubscription? _playerLoadedDataSubscription;
Expand Down Expand Up @@ -50,7 +51,7 @@ class WrappedPlayer {

set volume(double volume) {
_currentVolume = volume;
player?.volume = volume;
_gainNode?.gain.value = volume;
}

set balance(double balance) {
Expand All @@ -76,7 +77,6 @@ class WrappedPlayer {
// 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);
Expand All @@ -86,8 +86,11 @@ class WrappedPlayer {

final source = _audioContext!.createMediaElementSource(p);
_sourceNode = source;
_gainNode = _audioContext!.createGain();
_gainNode!.gain.value = _currentVolume;
_stereoPanner = _audioContext!.createStereoPanner();
source.connect(_stereoPanner!);
source.connect(_gainNode!);
_gainNode!.connect(_stereoPanner!);
_stereoPanner?.connect(_audioContext!.destination);

// Preload the source
Expand Down Expand Up @@ -181,6 +184,8 @@ class WrappedPlayer {

_sourceNode?.disconnect();
_sourceNode = null;
_gainNode?.disconnect();
_gainNode = null;
// Release `AudioElement` correctly (#966)
player?.src = '';
player?.remove();
Expand Down
Loading