Просмотр исходного кода

replay on play when video finished (#189)

Victor 6 лет назад
Родитель
Сommit
3caccc8f16
2 измененных файлов с 10 добавлено и 1 удалено
  1. 5 1
      lib/src/cupertino_controls.dart
  2. 5 0
      lib/src/material_controls.dart

+ 5 - 1
lib/src/cupertino_controls.dart

@@ -154,7 +154,6 @@ class _CupertinoControlsState extends State<CupertinoControls> {
                         _buildRemaining(iconColor)
                       ],
                     ),
-
             ),
           ),
         ),
@@ -496,6 +495,8 @@ class _CupertinoControlsState extends State<CupertinoControls> {
   }
 
   void _playPause() {
+    bool isFinished = _latestValue.position >= _latestValue.duration;
+
     setState(() {
       if (controller.value.isPlaying) {
         _hideStuff = false;
@@ -509,6 +510,9 @@ class _CupertinoControlsState extends State<CupertinoControls> {
             controller.play();
           });
         } else {
+          if (isFinished) {
+            controller.seekTo(Duration(seconds: 0));
+          }
           controller.play();
         }
       }

+ 5 - 0
lib/src/material_controls.dart

@@ -323,6 +323,8 @@ class _MaterialControlsState extends State<MaterialControls> {
   }
 
   void _playPause() {
+    bool isFinished = _latestValue.position >= _latestValue.duration;
+
     setState(() {
       if (controller.value.isPlaying) {
         _hideStuff = false;
@@ -336,6 +338,9 @@ class _MaterialControlsState extends State<MaterialControls> {
             controller.play();
           });
         } else {
+          if (isFinished) {
+            controller.seekTo(Duration(seconds: 0));
+          }
           controller.play();
         }
       }