Player constructor

Player({
  1. PlayerConfig config = const PlayerConfig(),
})

Implementation

Player({
  this.config = const PlayerConfig(),
}) {
  _initializationResult = _completer.future;
  _uuid = hashCode.toString();

  final mainChannel = ChannelManager.registerMethodChannel(
    name: Channels.main,
  );

  mainChannel
      .invokeMethod<bool>(
    Methods.createPlayer,
    Map<String, dynamic>.from(
      {
        'id': id,
        'playerConfig': config.toJson(),
      },
    ),
  )
      .then((value) {
    if (value == null || value == false) {
      _completer.complete(false);
      return;
    }

    _methodChannel = ChannelManager.registerMethodChannel(
      name: '${Channels.player}-$id',
      handler: _playerMethodCallHandler,
    );

    _eventChannel = ChannelManager.registerEventChannel(
      name: '${Channels.playerEvent}-$id',
    );
    _eventChannel.receiveBroadcastStream().listen(onPlatformEvent);

    _completer.complete(true);
  });
}