Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Minor cleanup
  • Loading branch information
stuartmorgan-g committed Feb 8, 2021
commit fdfde8b9665b75b2cd7e46682828f79afd21dabc
32 changes: 17 additions & 15 deletions packages/image_picker/image_picker/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class _MyHomePageState extends State<MyHomePage> {
dynamic _pickImageError;
bool isVideo = false;
VideoPlayerController? _controller;
late VideoPlayerController _toBeDisposed;
VideoPlayerController? _toBeDisposed;
String? _retrieveDataError;

final ImagePicker _picker = ImagePicker();
Expand All @@ -53,21 +53,23 @@ class _MyHomePageState extends State<MyHomePage> {
Future<void> _playVideo(PickedFile? file) async {
if (file != null && mounted) {
await _disposeVideoController();
late VideoPlayerController controller;
if (kIsWeb) {
_controller = VideoPlayerController.network(file.path);
// In web, most browsers won't honor a programmatic call to .play
// if the video has a sound track (and is not muted).
// Mute the video so it auto-plays in web!
// This is not needed if the call to .play is the result of user
// interaction (clicking on a "play" button, for example).
await _controller!.setVolume(0.0);
controller = VideoPlayerController.network(file.path);
} else {
_controller = VideoPlayerController.file(File(file.path));
await _controller!.setVolume(1.0);
controller = VideoPlayerController.file(File(file.path));
}
await _controller!.initialize();
await _controller!.setLooping(true);
await _controller!.play();
_controller = controller;
// In web, most browsers won't honor a programmatic call to .play
// if the video has a sound track (and is not muted).
// Mute the video so it auto-plays in web!
// This is not needed if the call to .play is the result of user
// interaction (clicking on a "play" button, for example).
final double volume = kIsWeb ? 0.0 : 1.0;
await controller.setVolume(volume);
await controller.initialize();
await controller.setLooping(true);
await controller.play();
setState(() {});
}
}
Expand Down Expand Up @@ -123,9 +125,9 @@ class _MyHomePageState extends State<MyHomePage> {

Future<void> _disposeVideoController() async {
if (_toBeDisposed != null) {
await _toBeDisposed.dispose();
await _toBeDisposed!.dispose();
}
_toBeDisposed = _controller!;
_toBeDisposed = _controller;
_controller = null;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/image_picker/image_picker/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ flutter:
uses-material-design: true

environment:
sdk: ">=2.12.0-259.8.beta <3.0.0"
sdk: ">=2.12.0-0 <3.0.0"
flutter: ">=1.10.0 <2.0.0"