setPlaylistMode method

  1. @override
Future<void> setPlaylistMode(
  1. PlaylistMode playlistMode, {
  2. bool synchronized = true,
})
override

Sets playlist mode.

Implementation

@override
Future<void> setPlaylistMode(PlaylistMode playlistMode,
    {bool synchronized = true}) {
  Future<void> function() async {
    if (disposed) {
      throw AssertionError('[Player] has been disposed');
    }
    await waitForPlayerInitialization;
    await waitForVideoControllerInitializationIfAttached;

    final file = 'loop-file'.toNativeUtf8();
    final playlist = 'loop-playlist'.toNativeUtf8();
    final yes = 'yes'.toNativeUtf8();
    final no = 'no'.toNativeUtf8();
    switch (playlistMode) {
      case PlaylistMode.none:
        {
          mpv.mpv_set_property_string(
            ctx,
            file.cast(),
            no.cast(),
          );
          mpv.mpv_set_property_string(
            ctx,
            playlist.cast(),
            no.cast(),
          );
          break;
        }
      case PlaylistMode.single:
        {
          mpv.mpv_set_property_string(
            ctx,
            file.cast(),
            yes.cast(),
          );
          mpv.mpv_set_property_string(
            ctx,
            playlist.cast(),
            no.cast(),
          );
          break;
        }
      case PlaylistMode.loop:
        {
          mpv.mpv_set_property_string(
            ctx,
            file.cast(),
            no.cast(),
          );
          mpv.mpv_set_property_string(
            ctx,
            playlist.cast(),
            yes.cast(),
          );
          break;
        }
      default:
        break;
    }
    calloc.free(file);
    calloc.free(playlist);
    calloc.free(yes);
    calloc.free(no);

    state = state.copyWith(playlistMode: playlistMode);
    if (!playlistModeController.isClosed) {
      playlistModeController.add(playlistMode);
    }
  }

  if (synchronized) {
    return lock.synchronized(function);
  } else {
    return function();
  }
}