setSources method
Future<RadioPlayerState>
setSources(
- List<
RadioSource> sources, { - int? initialIndex,
- bool autoPlay = false,
override
Replaces the source list; see FlutterRadioPlayer.setSources.
Implementation
@override
Future<RadioPlayerState> setSources(
List<RadioSource> sources, {
int? initialIndex,
bool autoPlay = false,
}) {
calls.add(
'setSources(${sources.length}'
'${initialIndex == null ? '' : ', initialIndex: $initialIndex'}'
'${autoPlay ? ', autoPlay: true' : ''})',
);
if (initialIndex != null &&
(initialIndex < 0 || initialIndex >= sources.length)) {
return Future.error(RangeError.index(initialIndex, sources));
}
if (sources.isEmpty) {
return _reply(RadioPlayerState(volume: _state.volume));
}
final previous = _state.currentSource;
final index = initialIndex ?? _follow(previous, sources);
final current = sources[index];
final keep =
previous != null &&
previous.id == current.id &&
previous.url == current.url &&
mapEquals(previous.headers, current.headers);
_state = keep
? _state.copyWith(
sources: List.unmodifiable(sources),
currentIndex: index,
)
: RadioPlayerState(
status: PlaybackStatus.paused,
sources: List.unmodifiable(sources),
currentIndex: index,
volume: _state.volume,
);
if (autoPlay) _startPlaying();
return _reply(_state);
}