setAudioSources method

bool setAudioSources(
  1. List<AudioSource> sources, {
  2. int initialIndex = 0,
  3. Duration initialPosition = Duration.zero,
  4. bool useLazyPreparation = true,
  5. Object? shuffleOrder,
})

Implementation

bool setAudioSources(
  List<AudioSource> sources, {
  int initialIndex = 0,
  Duration initialPosition = Duration.zero,
  bool useLazyPreparation = true,
  Object? shuffleOrder,
}) {
  final paths = sources.map((s) => _uriToEnginePath(s.uri)).toList();
  final ok = setPlaylist(paths);
  if (!ok) return false;

  if (sources.isEmpty) return false;
  final idx = initialIndex.clamp(0, sources.length - 1);
  final jumped = jumpToWithPosition(idx, initialPosition);

  if (!useLazyPreparation) {
    // Force preload behavior by briefly touching next/prev ordering.
    reshuffle();
  }

  if (shuffleOrder != null) {
    // Placeholder to keep API compatibility with caller; shuffle policy remains engine-defined.
  }

  return jumped;
}