setAudioSources method
Future<Duration?>
setAudioSources(
- List<
AudioSource> audioSources, { - bool preload = true,
- int? initialIndex,
- Duration? initialPosition,
- ShuffleOrder? shuffleOrder,
Clears the playlist and adds the given audioSources.
By default, this method will immediately start loading the initial
AudioSource and return its duration as soon as it is known, or null if
that information is unavailable. Set preload to false if you would
prefer to delay loading until some later point, either via an explicit
call to load or via a call to play which implicitly loads the audio.
If preload is false, a null duration will be returned. Note that the
preload option will automatically be assumed as true if playing is
currently true.
Optionally specify initialPosition and initialIndex to seek to an
initial position within a particular item (defaulting to position zero of
the first item).
When preload is true, this method may throw:
- PlayerException if the initial audio source was unable to be loaded.
- PlayerInterruptedException if another invocation of this method interrupted this invocation.
Implementation
Future<Duration?> setAudioSources(
List<AudioSource> audioSources, {
bool preload = true,
int? initialIndex,
Duration? initialPosition,
ShuffleOrder? shuffleOrder,
}) async {
_pluginLoadRequest?.interrupted = true;
if (_disposed) return null;
final loadRequest = _pluginLoadRequest = _PluginLoadRequest(
audioSources: audioSources,
preload: preload,
initialIndex: initialIndex,
initialPosition: initialPosition,
shuffleOrder: shuffleOrder ?? DefaultShuffleOrder(),
);
await _playlist._init(audioSources, loadRequest.shuffleOrder);
loadRequest.checkInterruption();
Duration? duration;
if (preload || playing) {
duration = await load();
} else {
await _setPlatformActive(false)?.catchError((dynamic e) async => null);
}
loadRequest.checkInterruption();
return duration;
}