initPlayerControls method

dynamic initPlayerControls(
  1. FlutterFlexPlayerController controller
)

Implementation

initPlayerControls(FlutterFlexPlayerController controller) {
  if (_isInitDone == true) {
    return;
  }
  _controller = controller;
  _streamSubscription?.cancel();
  combinedStream =
      dart.Rx.combineLatest2<InitializationEvent, PlayerState, CombinedState>(
    player.onInitialized,
    player.onPlayerStateChanged,
    (initializationEvent, playerState) =>
        CombinedState(initializationEvent, playerState),
  ).asBroadcastStream(); // Convert to broadcast stream

  // Subscribe to the combined stream
  _streamSubscription = combinedStream?.listen((combinedState) {
    if (combinedState.initializationEvent ==
            InitializationEvent.initialized &&
        combinedState.playerState == PlayerState.playing) {
      startTimer();
    }
    combinedStateController.add(combinedState);
  });

  _animationController = AnimationController(
    vsync: this,
    duration: const Duration(milliseconds: 200),
  );
  _playPauseController = AnimationController(
    vsync: this,
    duration: const Duration(milliseconds: 200),
  );
  _playerStateSubscription = _controller.onPlayerStateChanged.listen((state) {
    if (state == PlayerState.playing) {
      _playPauseController.reverse();
    } else {
      _playPauseController.forward();
    }
    if (state == PlayerState.buffering) {
      isControlsVisible.value = true;
      _animationController.forward();
    }
  });

  _playPauseController.forward();
  _animationController.forward();
  if (_controller.isPlaying) {
    _playPauseController.reverse();
  }
  startTimer();
  _isInitDone = true;
}