Skip to content

Commit

Permalink
Merge pull request #45 from resucutie/resucutie/fix-video-playing-on-…
Browse files Browse the repository at this point in the history
…wrong-routes

Fix video still playing whenever it is hidden under view
  • Loading branch information
resucutie authored Dec 22, 2024
2 parents 8bdbe97 + a67e9c3 commit 9219d67
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
15 changes: 14 additions & 1 deletion lib/components/video_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:io';
import 'package:chewie/chewie.dart';
import 'package:flutter/material.dart';
import 'package:video_player/video_player.dart';
import 'package:visibility_detector/visibility_detector.dart';

class VideoView extends StatefulWidget {
const VideoView(this.path, {super.key, this.showControls = true, this.soundOnStart = true, this.playOnStart = true});
Expand Down Expand Up @@ -53,7 +54,19 @@ class VideoViewState extends State<VideoView> {
Widget build(BuildContext context) {
return AspectRatio(
aspectRatio: _videoController.value.aspectRatio,
child: _isLoaded ? Chewie(controller: _chewieController,) : const SizedBox(height: 0,)
child: _isLoaded ? VisibilityDetector(
key: Key("unique key"),
onVisibilityChanged: (info) {
debugPrint("${info.visibleFraction} of my widget is visible");
if(info.visibleFraction == 0){
_videoController.pause();
}
else{
_videoController.play();
}
},
child: Chewie(controller: _chewieController,)
): const SizedBox(height: 0,)
);
}
}
8 changes: 8 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1323,6 +1323,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.3.3"
visibility_detector:
dependency: "direct main"
description:
name: visibility_detector
sha256: dd5cc11e13494f432d15939c3aa8ae76844c42b723398643ce9addb88a5ed420
url: "https://pub.dev"
source: hosted
version: "0.4.0+2"
vm_service:
dependency: transitive
description:
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ dependencies:
fvp: ^0.28.0
video_player: ^2.9.2
chewie: ^1.8.5
visibility_detector: ^0.4.0+2
fc_native_video_thumbnail: ^0.16.1

dev_dependencies:
Expand Down

0 comments on commit 9219d67

Please sign in to comment.