YSVideoView.dart 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import 'package:flutter/material.dart';
  2. import 'package:video_player/video_player.dart';
  3. class YSVideoView extends StatefulWidget {
  4. final VideoPlayerController player;
  5. const YSVideoView({Key? key, required this.player}) : super(key: key);
  6. @override
  7. YSVideoViewState createState() => YSVideoViewState();
  8. }
  9. class YSVideoViewState extends State<YSVideoView> {
  10. @override
  11. Widget build(BuildContext context) {
  12. return ClipRRect(
  13. borderRadius: const BorderRadius.all(Radius.circular(50)),
  14. child: GestureDetector(
  15. onLongPressStart: (value){
  16. widget.player.setPlaybackSpeed(2);
  17. },
  18. onLongPressEnd: (value){
  19. widget.player.setPlaybackSpeed(1);
  20. },
  21. onHorizontalDragEnd: (value){
  22. int seconds1 = widget.player.value.position.inSeconds;
  23. int seconds2 = widget.player.value.duration.inSeconds;
  24. int velocity = (value.primaryVelocity??0.0)~/100;
  25. int number = (seconds2/100*velocity)~/1;
  26. // LogUtil.d('$seconds1=======$seconds2=======$velocity=======$number');
  27. if(seconds1<=1)return;
  28. widget.player.seekTo(Duration(seconds: seconds1+number));
  29. },
  30. child: Container(
  31. color: Colors.white,
  32. child: VideoPlayer(widget.player),
  33. ),
  34. ),
  35. );
  36. }
  37. }