removeAt method

bool removeAt(
  1. int index
)

Removes the source at the specified index

Returns true if successful, false if the index is out of bounds

Implementation

bool removeAt(int index) {
  if (_sources.isEmpty || index < 0 || index >= _sources.length) {
    return false;
  }

  final newSources = List<AudioSource>.from(_sources);
  newSources.removeAt(index);

  // Adjust current index if necessary
  if (index < _currentIndex) {
    _currentIndex--;
  } else if (index == _currentIndex) {
    // If we removed the current item, stay at the same index
    // (which now points to the next item) unless we removed the last item
    if (_currentIndex >= newSources.length) {
      _currentIndex = newSources.isEmpty ? -1 : newSources.length - 1;
    }
  }

  _updateSources(newSources);
  return true;
}