remove method
Future<void>
remove(
- int index, {
- bool synchronized = true,
})
override
Removes the Media at specified index from the Player's playlist.
Implementation
@override
Future<void> remove(int index, {bool synchronized = true}) {
Future<void> function() async {
if (disposed) {
throw AssertionError('[Player] has been disposed');
}
await waitForPlayerInitialization;
await waitForVideoControllerInitializationIfAttached;
// If we remove the last item in the playlist while playlist mode is none or single, then playback will stop.
// In this situation, the playlist doesn't seem to be updated, so we manually update it.
if (state.playlist.index == index &&
state.playlist.medias.length - 1 == index &&
[
PlaylistMode.none,
PlaylistMode.single,
].contains(state.playlistMode)) {
state = state.copyWith(
// Allow playOrPause /w state.completed code-path to play the playlist again.
completed: true,
playlist: state.playlist.copyWith(
medias: state.playlist.medias.sublist(
0,
state.playlist.medias.length - 1,
),
index: state.playlist.medias.length - 2 < 0
? 0
: state.playlist.medias.length - 2,
),
);
if (!completedController.isClosed) {
completedController.add(true);
}
if (!playlistController.isClosed) {
playlistController.add(state.playlist);
}
}
final command = 'playlist-remove $index'.toNativeUtf8();
mpv.mpv_command_string(
ctx,
command.cast(),
);
calloc.free(command.cast());
}
if (synchronized) {
return lock.synchronized(function);
} else {
return function();
}
}