broswer.dart 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. part of 'data_host.dart';
  2. class _VidDataHostBroswer implements VidDataHostInterface {
  3. _VidDataHostBroswer(this.url);
  4. @override
  5. final String url;
  6. VidUsImageData? _data;
  7. @override
  8. int get frameCount => _data!.imageCount;
  9. @override
  10. VidUsProbe get probe => _data!.probe;
  11. @override
  12. Future<VidUsImageData?> getData() async => _data;
  13. @override
  14. Future<VidUsImage> getFrame<TProcessor extends VidFrameProcessor>(
  15. int index, {
  16. List<TProcessor>? processors,
  17. }) async {
  18. if (_data == null) {
  19. throw Exception(
  20. "[VidDataHost] getFrame: must call load first and data is not null.");
  21. }
  22. return _data!.getImage(index);
  23. }
  24. @override
  25. Future<VidDataHostLoadInfo?> load() async {
  26. final bytes = await VidFileDownloader.download(url);
  27. if (bytes != null && bytes.isNotEmpty) {
  28. _data = VidUsImageData(bytes);
  29. final info = VidDataHostLoadInfo(_data!.probe);
  30. return info;
  31. }
  32. return null;
  33. }
  34. @override
  35. Future<void> release() async {
  36. _data = null;
  37. }
  38. }