startPlayer method

void startPlayer(
  1. String url, {
  2. bool autoPlay = true,
})

Starts the player with a given url and optional autoPlay flag.

This method initializes the player and begins streaming the content from the specified URL. It listens for various events such as player state changes, quality updates, and errors, and broadcasts them via the respective streams.

Implementation

void startPlayer(String url, {bool autoPlay = true}) {
  _controller.createPlayer(url);
  _controller.startPlayer(
    url,
    autoPlay: autoPlay,
    onData: (data) async {
      _parseEvents(data);
    },
    onError: (error) {},
  );

  // Periodically update the player's position.
  _positionStreamSubs?.cancel();
  _positionStreamSubs = Stream.periodic(
    const Duration(milliseconds: 100),
  ).listen(
    (event) async {
      positionStream.add(await _controller.getPosition());
    },
  );
}