shell.dart 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. part of 'data_host.dart';
  2. class _VidDataHostShell implements VidDataHostInterface {
  3. _VidDataHostShell(this.url);
  4. static PlatformService get _platform => VidDataHostEnv.platformGetter!.call();
  5. VidUsImageData? _data;
  6. @override
  7. final String url;
  8. @override
  9. int get frameCount => _data == null ? -1 : _data!.imageCount;
  10. @override
  11. VidUsProbe get probe => _data!.probe;
  12. @override
  13. Future<VidUsImageData?> getData() async => _data;
  14. @override
  15. Future<VidDataHostLoadInfo?> load() async {
  16. final rst = await getVidFile(url);
  17. if (rst == null || rst.isEmpty) return null;
  18. final buffer = const Base64Decoder().convert(rst);
  19. _data = VidUsImageData(buffer);
  20. final info = VidDataHostLoadInfo(_data!.probe);
  21. return info;
  22. }
  23. ///获取vid文件
  24. Future<String?> getVidFile(String url, {int times = 0}) async {
  25. try {
  26. return await _platform.getVidFile(url);
  27. } catch (e) {
  28. logger.e('_VidDataHostShell load $times ex:', e);
  29. if (times < 2) {
  30. return await getVidFile(url, times: times++);
  31. }
  32. return null;
  33. }
  34. }
  35. @override
  36. Future<VidUsImage?> getFrame(int index) async => _data?.getImage(index);
  37. @override
  38. Future<void> release() async {
  39. _data = null;
  40. }
  41. }