startPlayer method
void
startPlayer(})
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]");
}
}