12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- part of 'data_host.dart';
- class _VidDataHostShell implements VidDataHostInterface {
- _VidDataHostShell(this.url);
- static PlatformService get _platform => VidDataHostEnv.platformGetter!.call();
- VidUsImageData? _data;
- @override
- final String url;
- @override
- int get frameCount => _data == null ? -1 : _data!.imageCount;
- @override
- VidUsProbe get probe => _data!.probe;
- @override
- Future<VidUsImageData?> getData() async => _data;
- @override
- Future<VidDataHostLoadInfo?> load() async {
- final rst = await getVidFile(url);
- if (rst == null || rst.isEmpty) return null;
- final buffer = const Base64Decoder().convert(rst);
- _data = VidUsImageData(buffer);
- final info = VidDataHostLoadInfo(_data!.probe);
- return info;
- }
- ///获取vid文件
- Future<String?> getVidFile(String url, {int times = 0}) async {
- try {
- return await _platform.getVidFile(url);
- } catch (e) {
- logger.e('_VidDataHostShell load $times ex:', e);
- if (times < 2) {
- return await getVidFile(url, times: times++);
- }
- return null;
- }
- }
- @override
- Future<VidUsImage?> getFrame(int index) async => _data?.getImage(index);
- @override
- Future<void> release() async {
- _data = null;
- }
- }
|