YSVideoDetail.dart 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import 'dart:io';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter_vr/tools/YSTools.dart';
  4. import 'package:flutter_vr/video/view/YSVideoProgressView.dart';
  5. import 'package:flutter_vr/video/view/YSVideoView.dart';
  6. import 'package:video_player/video_player.dart';
  7. import '../tools/connectManager.dart';
  8. class YSVideoDetail extends StatefulWidget {
  9. final Map video;
  10. const YSVideoDetail({Key? key, required this.video}) : super(key: key);
  11. @override
  12. YSVideoDetailState createState() => YSVideoDetailState();
  13. }
  14. class YSVideoDetailState extends State<YSVideoDetail> {
  15. VideoPlayerController? _playerController;
  16. late ConnectManager _connectManager;
  17. @override
  18. void initState() {
  19. AppUtil.H();
  20. _listenBlueTools();
  21. Future.delayed(const Duration(seconds: 0)).then((value) {
  22. _getPlayer();
  23. });
  24. super.initState();
  25. }
  26. _listenBlueTools() {
  27. _connectManager = ConnectManager(GattCallback( //1.实例化连接管理类,并监听连接状态
  28. onDeviceNotFind: () { //没找到设备
  29. LogUtil.d('onDeviceNotFind>>>>');
  30. },
  31. onConnected: () { //连接成功回调
  32. LogUtil.d('onConnected>>>>');
  33. },
  34. onDisconnect: () { //连接关闭回调
  35. LogUtil.d('onDisconnect>>>>');
  36. },
  37. onRead: (MessageData data) { //设备发过来的数据
  38. LogUtil.d('onRead>>>>$data');
  39. }
  40. ));
  41. if(!_connectManager.isConnecting){
  42. _connectManager.start("Xiaomi Smart Band 8 Pro 0154"); //2.开始连接蓝牙设备,T11302002020169为蓝牙设备名称
  43. }
  44. }
  45. @override
  46. void dispose() {
  47. AppUtil.V();
  48. _playerController?.dispose();
  49. super.dispose();
  50. }
  51. _getPlayer() async{
  52. _playerController = VideoPlayerController.file(File(widget.video['path']))..initialize().then((_) {
  53. _playerController?.setLooping(true);
  54. _playerController?.play();
  55. setState(() {});
  56. });
  57. setState(() {});
  58. }
  59. @override
  60. Widget build(BuildContext context) {
  61. return Scaffold(
  62. backgroundColor: Colors.black,
  63. body: Stack(
  64. children: [
  65. if(_playerController!=null)Container(
  66. padding: const EdgeInsets.all(50),
  67. child: Row(
  68. children: [
  69. Expanded(child: YSVideoView(player: _playerController!,)),
  70. const SizedBox(width: 50,),
  71. Expanded(child: YSVideoView(player: _playerController!,)),
  72. ],
  73. ),
  74. ),
  75. Container(
  76. padding: EdgeInsets.only(top: ysTOP(context)+5),
  77. child: GestureDetector(
  78. onTap: (){
  79. Navigator.pop(context);
  80. },
  81. behavior: HitTestBehavior.opaque,
  82. child: Row(
  83. children: [
  84. const Icon(Icons.chevron_left,size: 40,color: Colors.white,),
  85. Expanded(child: Text(widget.video['name'],style: const TextStyle(fontSize: 15,color: Colors.white),maxLines: 1,))
  86. ],
  87. ),
  88. ),
  89. ),
  90. if(_playerController!=null)YSVideoProgressView(playerController: _playerController!)
  91. ],
  92. ),
  93. );
  94. }
  95. }