File tree 1 file changed +18
-0
lines changed
1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -44,6 +44,10 @@ class NativeVideoViewerPage extends HookConsumerWidget {
44
44
final lastVideoPosition = useRef (- 1 );
45
45
final isBuffering = useRef (false );
46
46
47
+ // Used to track whether the video should play when the app
48
+ // is brought back to the foreground
49
+ final shouldPlayOnForeground = useRef (true );
50
+
47
51
// When a video is opened through the timeline, `isCurrent` will immediately be true.
48
52
// When swiping from video A to video B, `isCurrent` will initially be true for video A and false for video B.
49
53
// If the swipe is completed, `isCurrent` will be true for video B after a delay.
@@ -368,6 +372,20 @@ class NativeVideoViewerPage extends HookConsumerWidget {
368
372
const [],
369
373
);
370
374
375
+ useOnAppLifecycleStateChange ((_, state) async {
376
+ if (state == AppLifecycleState .resumed && shouldPlayOnForeground.value) {
377
+ controller.value? .play ();
378
+ } else if (state == AppLifecycleState .paused) {
379
+ final videoPlaying = await controller.value? .isPlaying ();
380
+ if (videoPlaying ?? true ) {
381
+ shouldPlayOnForeground.value = true ;
382
+ controller.value? .pause ();
383
+ } else {
384
+ shouldPlayOnForeground.value = false ;
385
+ }
386
+ }
387
+ });
388
+
371
389
return Stack (
372
390
children: [
373
391
// This remains under the video to avoid flickering
You can’t perform that action at this time.
0 commit comments