startPlayer method

  1. @override
void startPlayer(
  1. String url, {
  2. required bool autoPlay,
  3. void onData(
    1. dynamic
    )?,
  4. void onError(
    1. dynamic
    )?,
})
override

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 and errors, and triggers the provided callbacks.

Implementation

@override
void startPlayer(
  String url, {
  required bool autoPlay,
  void Function(dynamic)? onData,
  void Function(dynamic)? onError,
}) async {
  try {
    await _methodChannel.invokeMethod("startPlayer", {
      "url": url,
      "autoPlay": autoPlay,
    });

    // Cancel any existing subscription before creating a new one.
    playerStateSubscription?.cancel();
    playerStateSubscription = _eventChannel
        .receiveBroadcastStream()
        .listen(onData, onError: onError);
  } catch (e) {
    throw Exception(
        "Unable to start the player with the provided URL [Start Player]");
  }
}