dint-dev / universal_html

Cross-platform 'dart:html'.
https://pub.dev/packages/universal_html
Apache License 2.0
201 stars 60 forks source link

The getter 'duration' isn't defined for the class 'MediaElement'. #88

Open shMolaee opened 10 months ago

shMolaee commented 10 months ago

I wrote this method to get media time in Flutter, everything is fine on the web, but it gives me this error on other platforms.

code: Future<double> getWebDuration(Uint8List bytes, MediaType mediaType) async { final blob = Blob([bytes]); final url = Url.createObjectUrlFromBlob(blob); final audio = (mediaType == MediaType.video ? VideoElement() : AudioElement()) ..src = url ..autoplay = false; document.body?.append(audio); final duration = await Future(() { final completer = Completer<double>(); audio.onLoadedData.listen((event) { late final duration; if (isWeb) { duration = audio.duration; } Url.revokeObjectUrl(url); audio.remove(); completer.complete(duration.toDouble()); }); return completer.future; }); return duration; }

lib/utils/file/media_duration.dart(25,26): error G4127D1E8: The getter 'duration' isn't defined for the class 'MediaElement'.

Megatronicus commented 10 months ago

Is that similar to this https://github.com/dint-dev/universal_html/issues/86