preparePlayerController method

  1. @override
Future<VlcPlayerController> preparePlayerController(
  1. {required AppModel appModel,
  2. required WidgetRef ref,
  3. required MediaItem item}
)
override

Get the player controller to be used when a media item is loaded up,

Implementation

@override
Future<VlcPlayerController> preparePlayerController({
  required AppModel appModel,
  required WidgetRef ref,
  required MediaItem item,
}) async {
  String dataSource = await getDataSource(item);
  String audioUrl = await getAudioUrl(item, dataSource);

  int startTime = item.position;
  if (item.duration - item.position < 60) {
    startTime = 0;
  }

  List<String> videoParams = [
    VlcVideoOptions.dropLateFrames(false),
    VlcVideoOptions.skipFrames(false),
  ];
  List<String> advancedParams = [
    '--start-time=$startTime',
    VlcAdvancedOptions.networkCaching(20000),
  ];
  List<String> soutParams = [
    '--start-time=$startTime',
    VlcStreamOutputOptions.soutMuxCaching(20000),
  ];
  List<String> audioParams = [
    '--input-slave=$audioUrl',
    '--sub-track=99999',
    if (appModel.playerUseOpenSLES) '--aout=opensles',
  ];

  return VlcPlayerController.network(
    dataSource,
    hwAcc: appModel.playerHardwareAcceleration ? HwAcc.auto : HwAcc.disabled,
    options: VlcPlayerOptions(
      advanced: VlcAdvancedOptions(advancedParams),
      audio: VlcAudioOptions(audioParams),
      sout: VlcStreamOutputOptions(soutParams),
      video: VlcVideoOptions(videoParams),
    ),
  );
}