diff options
Diffstat (limited to 'lib/data/data_providers/mediaplayer_position_notifier.dart')
-rw-r--r-- | lib/data/data_providers/mediaplayer_position_notifier.dart | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/lib/data/data_providers/mediaplayer_position_notifier.dart b/lib/data/data_providers/mediaplayer_position_notifier.dart new file mode 100644 index 0000000..be896da --- /dev/null +++ b/lib/data/data_providers/mediaplayer_position_notifier.dart @@ -0,0 +1,29 @@ +import 'dart:async'; +import 'package:flutter_ics_homescreen/export.dart'; + +class MediaPlayerPositionNotifier extends Notifier<Duration> { + Timer? positionTimer; + + @override + Duration build() { + return Duration.zero; + } + + void set(Duration position) { + state = position; + } + + void play() { + positionTimer ??= + Timer.periodic(const Duration(milliseconds: 250), (timer) { + state = state + const Duration(milliseconds: 250); + }); + } + + void pause() { + if (positionTimer != null) { + positionTimer!.cancel(); + positionTimer = null; + } + } +} |