setSourceBytes method

Future<void> setSourceBytes(
  1. Uint8List bytes, {
  2. String? mimeType,
})

Implementation

Future<void> setSourceBytes(Uint8List bytes, {String? mimeType}) async {
  if (!kIsWeb &&
      (defaultTargetPlatform == TargetPlatform.iOS ||
          defaultTargetPlatform == TargetPlatform.macOS ||
          defaultTargetPlatform == TargetPlatform.linux)) {
    // Convert to file as workaround
    final tempDir = (await getTemporaryDirectory()).path;
    final bytesHash = Object.hashAll(bytes)
        .toUnsigned(20)
        .toRadixString(16)
        .padLeft(5, '0');
    final file = File('$tempDir/$bytesHash');
    await file.writeAsBytes(bytes);
    await setSourceDeviceFile(file.path, mimeType: mimeType);
  } else {
    _source = BytesSource(bytes, mimeType: mimeType);
    await _completePrepared(
      () => _platform.setSourceBytes(playerId, bytes, mimeType: mimeType),
    );
  }
}