YSVideoProgressView.dart 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import 'package:flutter/material.dart';
  2. import 'package:video_player/video_player.dart';
  3. class YSVideoProgressView extends StatefulWidget {
  4. final VideoPlayerController playerController;
  5. const YSVideoProgressView({Key? key, required this.playerController}) : super(key: key);
  6. @override
  7. YSVideoProgressViewState createState() => YSVideoProgressViewState();
  8. }
  9. class YSVideoProgressViewState extends State<YSVideoProgressView> {
  10. String _startTime = '00:00:00';
  11. @override
  12. void initState() {
  13. widget.playerController.addListener(() {
  14. Duration position = widget.playerController.value.position;
  15. _startTime = '${'${position.inHours}'.padLeft(2,'0')}:${'${position.inMinutes}'.padLeft(2,'0')}:${'${position.inSeconds}'.padLeft(2,'0')}';
  16. setState(() {});
  17. });
  18. super.initState();
  19. }
  20. @override
  21. Widget build(BuildContext context) {
  22. return Container(
  23. margin: EdgeInsets.only(top: MediaQuery.of(context).size.height-50,left: 15,right: 15),
  24. child: Row(
  25. children: [
  26. SizedBox(
  27. width: 100,
  28. child: Row(
  29. children: [
  30. GestureDetector(
  31. onTap: (){
  32. widget.playerController.value.isPlaying?widget.playerController.pause() : widget.playerController.play();
  33. setState(() {});
  34. },
  35. child: Icon(widget.playerController.value.isPlaying?Icons.pause:Icons.play_arrow,size: 25,color: Colors.white,),
  36. ),
  37. Container(
  38. alignment: Alignment.center,
  39. width: 75,
  40. child: Text(_startTime,style: const TextStyle(fontSize: 12,color: Colors.white),),
  41. )
  42. ],
  43. ),
  44. ),
  45. SizedBox(
  46. width: MediaQuery.of(context).size.width-130,
  47. height:6.5,
  48. child: VideoProgressIndicator(
  49. widget.playerController,
  50. allowScrubbing: true,
  51. colors: const VideoProgressColors(playedColor: Colors.white,backgroundColor: Colors.black),
  52. )
  53. ),
  54. ],
  55. ),
  56. );
  57. }
  58. }