universal_html
universal_html copied to clipboard
The getter 'duration' isn't defined for the class 'MediaElement'.
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'.