create method

  1. @override
Future<int> create(
  1. DataSource dataSource
)
override

Creates an instance of a video player and returns its textureId.

Implementation

@override
Future<int> create(DataSource dataSource) async {
  final int textureId = _textureCounter;
  _textureCounter++;

  late String uri;
  switch (dataSource.sourceType) {
    case DataSourceType.network:
      // Do NOT modify the incoming uri, it can be a Blob, and Safari doesn't
      // like blobs that have changed.
      uri = dataSource.uri ?? '';
      headers = dataSource.httpHeaders;
      break;
    case DataSourceType.asset:
      String assetUrl = dataSource.asset!;
      if (dataSource.package != null && dataSource.package!.isNotEmpty) {
        assetUrl = 'packages/${dataSource.package}/$assetUrl';
      }
      // 'webOnlyAssetManager' is only in the web version of dart:ui
      // ignore: undefined_prefixed_name
      assetUrl = ui.webOnlyAssetManager.getAssetUrl(assetUrl).toString();
      uri = assetUrl;
      break;
    case DataSourceType.file:
      return Future<int>.error(UnimplementedError(
          'web implementation of video_player cannot play local files'));
    case DataSourceType.contentUri:
      return Future<int>.error(UnimplementedError(
          'web implementation of video_player cannot play content uri'));
  }

  final _VideoPlayer player =
      _VideoPlayer(uri: uri, textureId: textureId, headers: headers);

  await player.initialize();

  _videoPlayers[textureId] = player;
  return textureId;
}