insert method
Inserts media at index in the playlist: the entry there and the
ones after it move down by one, and index equal to the playlist
length appends, as add does. The current entry keeps playing.
The per-entry options of media ride along as in add. To play it
next, pass state.playback.playlist.index + 1.
Throws RangeError if index is outside 0..length.
Implementation
Future<void> insert(int index, Media media) async {
_checkNotDisposed();
RangeError.checkNotNegative(index, 'index');
_validateLoadOptions(media);
// The same staleness rule as [add].
final load = _transport.snapshotLoad();
await _gate();
// mpv's own count, as in [move]: the state can lag an add in flight.
final (rc, count) = await _calls.get(
'playlist-count',
MpvFormat.mpvFormatInt64,
);
if (_disposed) return;
RangeError.checkValueInInterval(
index,
0,
_entries.fromCoreCount(rc < 0 ? 0 : count as int),
'index',
);
await _addEntry(media, load, at: _entries.toCore(index));
}