callBackWhenVideoStateChange method

void callBackWhenVideoStateChange({
  1. required dynamic onVideoStateChange(
    1. VideoState state
    )?,
})

Implementation

void callBackWhenVideoStateChange({
  required Function(VideoState state)? onVideoStateChange,
}) {
  controller.addJavaScriptHandler(
    handlerName: 'onVideoStateChange',
    callback: (args) {
      final String state = args.first;
      VideoState? videoState;

      switch (state) {
        case 'playing':
          videoState = VideoState.playing;
          break;
        case 'paused':
          videoState = VideoState.paused;
          break;
        case 'muted':
          videoState = VideoState.muted;
          break;
        case 'unmuted':
          videoState = VideoState.unmuted;
          break;
      }

      if (videoState != null) {
        onVideoStateChange?.call(videoState);
        print('<<< Video state changed: $state >>>');
      }

      return null;
    },
  );
}