release method

Future<void> release()

Implementation

Future<void> release() async {
  pause();
  // Need to reset pausedAt, otherwise resume will start at the old position
  // after release.
  _pausedAt = null;

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

  await _playerLoadedDataSubscription?.cancel();
  _playerLoadedDataSubscription = null;
  await _playerEndedSubscription?.cancel();
  _playerEndedSubscription = null;
  await _playerSeekedSubscription?.cancel();
  _playerSeekedSubscription = null;
  await _playerPlaySubscription?.cancel();
  _playerPlaySubscription = null;
  await _playerErrorSubscription?.cancel();
  _playerErrorSubscription = null;
}